我有一个LinkedList
,格式如下:
List<String> tables = new LinkedList<String>();
有时,
表格
列表看起来像这样,意味着它内部有所有的空字符串值 -[null, null]
有没有直接的方法来识别tables
列表是否包含所有元素都是null
字符串,如果是,则返回true,否则返回false。
我能想到的一种方法是不断迭代它并查看它是否具有null字符串,然后相应地返回true或false。
更新:-
public static void main(String[] args) {
String table_1 = null;
String table_2 = "hello";
List<String> tables = new LinkedList<String>();
tables.add(table_1);
tables.add(table_2);
boolean ss = isAllNull(tables);
System.out.println(ss);
}
public static boolean isAllNull(Iterable<?> list) {
for (Object obj : list) {
if (obj != null)
return false;
}
return true;
}