java - how to check if an array 2D (arrayList of arrayList) contains an array of null value? -



java - how to check if an array 2D (arrayList of arrayList) contains an array of null value? -

i have arraylist of arraylist , want check if array (sublist) contains null value. problem when first sublist contains null, works if sec sublist, doesn't work because first sublist contain object o

arraylist<arraylist<type>> array = new arraylist<arraylist<type>>(); arraylist<type> sublist = new arraylist<type>(); (int = 0; <= array.size(); i++) { sublist=array.get(i); if (sublist != null) { (object o : sublist) { if (o != null) homecoming false; } } } homecoming true;

i figure out that:

if (o != null) homecoming false;

makes loop goes out. how go on loop

edit:

public boolean containsonlynull(arraylist<type> sublist) { (object o : sublist) { if (o != null) homecoming false; } homecoming true; } public boolean isempty() { arraylist<type> sublist = new arraylist<type>(); (int = 0; <= array.size(); i++) { sublist = array.get(i); if (sublist != null) { if(!containsonlynull(sublist)) homecoming false; } homecoming true; } homecoming true; }

you can utilize flag instead of homecoming statement:

arraylist<arraylist<type>> array = new arraylist<arraylist<type>>(); arraylist<type> sublist = new arraylist<type>(); boolean hasobject = false; (int = 0; <= array.size(); i++) { sublist=array.get(i); if (sublist != null) { (object o : sublist) { if (o != null) hasobject = true; } } } homecoming hasobject;

in version, returns true if in 1 of list null element occurs.

but easier solution extract inner loop method , utilize homecoming statement.

private boolean containsonlynull(list<type list) { //boolean allnull = true; (object o : sublist) { if (o != null) //allnull = false; homecoming false; } } //return allnull; homecoming true; }

your method:

arraylist<arraylist<type>> array = new arraylist<arraylist<type>>(); arraylist<type> sublist = new arraylist<type>(); boolean hasobject = false; (int = 0; <= array.size(); i++) { sublist=array.get(i); if (sublist != null) { if (!containsonlynull(sublist)) homecoming false; //or whatever semantic } } homecoming true;

java arraylist multidimensional-array

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -