Java arraylists search and replace elements in each list -


i have lists in arraylist, elements recurrent in lists. search specified element , replace second element after in lists.

for (int lj = 0; lj < arraynum; lj++) {     (int lk = 0; lk < adjlists.get(lj).size(); lk+=3) {         if (adjlists.get(lj).get(lk) == adjlists.get(l).get(h)             && adjlists.get(lj).get(lk + 1) == adjlists.get(l).get(h + 1)) {             adjlists.get(lj).set(lk + 2, 1);         }     } } 

example - search 154 , 358, zeros should changed 1:

[288, 362, 0, 365, 85, 0, 137, 10, 0, 154, 358, 1]

[285, 226, 0, 137, 10, 0, 20, 30, 1, 387, 297, 0, 154, 358, 1]

this code 1 match, not matches.

look @ working example. in for-each loop iterate on each of arraylists , instance of them. replace 0 1 while there 0 in list.

list<list<integer>> list = new arraylist<>(); list.add(arrays.aslist(288, 362, 0, 365, 85, 0, 137, 10, 0, 154, 358, 1)); list.add(arrays.aslist(285, 226, 0, 137, 10, 0, 20, 30, 1, 387, 297, 0, 154, 358, 1));  // real stuff happens for(list<integer> arraylist:list) {     while(arraylist.contains(0))     {         arraylist.set(arraylist.indexof(0), 1);     } } 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -