If an ArrayList has been instantiated, it is definitely not equal to null. Since the toString method can be executed without reporting an error, it must have been instantiated. Because toString is a method of the top-level parent class Object, how can an uninstantiated object have this method.
ArrayList list = new ArrayList();
System.out.println(list == null); // false
ArrayList list1 = null;
System.out.println(list1.toString()); // 空指针
if(map.get(a)==null)
Can’t you tell whether it is empty?In Java, null and empty array are not the same concept. If you want to determine whether the array is empty, you can write it like this.
`
if (map.get(a) == null || map.get(a).size() == 0)
`
If an ArrayList has been instantiated, it is definitely not equal to null.
Since the toString method can be executed without reporting an error, it must have been instantiated. Because toString is a method of the top-level parent class Object, how can an uninstantiated object have this method.
map.get(a).toString().equals(""); is always false
The result you print out
a**[]
可以看出来map.get(a).toString()
不是空字符串,而是[]
,因此"[]".equals("")
is always falsemap.get(a)! =null; always true
If
map.get(a).toString()
没抛空指针异常,那么map.get(a)
must be non-emptyJudgment empty
If the value corresponding to the key is always ArrayList, then you can use the following method: