What is difference between null and empty list?

后端 未结 4 1977
别跟我提以往
别跟我提以往 2021-01-19 01:14
List> pcList = null;
Map pcMap = new HashMap();
ComputerConfigurations tempPC = null;

if         


        
4条回答
  •  隐瞒了意图╮
    2021-01-19 02:05

    Here is an example based answer. In this example below pcList is just initialized and is pointed to null(java do this for you, if it's a static or class member) since there are no empty list or values assigned to it.

    List> pcList;
    

    Right now, pcList is assigned a new empty ArrayList. It does not have any values yet, but all positions in the list are empty and this pcList with the datatype ArrayList is pointed towards this new empty ArrayList.

    List> pcList = new ArrayList<>();
    

    If an Object reference has been declared but not instantiated, its value is null.

提交回复
热议问题