What is difference between null and empty list?

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

if         


        
4条回答
  •  花落未央
    2021-01-19 02:02

    You're not initialising pcList at any point. Try this:

        final List> pcList = new LinkedList<>();
        Map pcMap = new HashMap();
        ComputerConfigurations tempPC = null;
    
        if (historyList != null) {
            Iterator iterator = historyList.iterator();
            while (iterator.hasNext()) {
                tempPC = (ComputerConfigurations) iterator.next();
                pcMap.put(tempPC.getEnvironment(), tempPC);
                pcList.add((Map) pcMap);
            }
        }
    

提交回复
热议问题