java - How to check a List whether it contains all the elements as NULL string? -


i having linkedlist -

list<string> tables = new linkedlist<string>(); 

sometimes, tables list like, meaning have null string values inside -

[null, null] 

is there direct way of identifying if tables list has elements null string, return true, otherwise return false.

one way can think of keep on iterating , see whether has null string or not , return true or false accordingly.

update:-

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) { (object obj : list) {     if (obj != null)     return false; }  return true; } 

yes thinking good, better if make part of utility class

public static boolean isallnull(iterable<?> list){     for(object obj : list){         if(obj != null)             return false;     }      return true; } 

note util accepts iterable interface work in wider scope.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -