我想知道 ArrayList 中的对象是否为 null。如果它为空,那么它不应该执行任何操作。示例:
if(!(theList.get(theIndexofObject) == null)){
do something...
}
else{
do nothing...
}
这不起作用,因为它会引发“.get()”方法的异常。有什么想法可以解决这个问题吗?
最佳答案
使用contains()
列表方法:
boolean contains(Object o)
关于java - 如何知道ArrayList中指定的对象是否为null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6568662/