java - Iterator and If -
i got little problem programm.
iterator<mystring> = globalset.iterator(); iterator<string> it2 = globalarray.iterator(); while(it.hasnext() && it2.hasnext()) { system.out.println(it2.next()); if(it.next().getline().contains(it2.next()) == true) { //it.remove(); } } if disable if clause output correct , looks this:
1;trägertour 096;1410;autotour 1n410; 2;trägertour 097;1410;autotour 1n410; 3;trägertour 098;1410;autotour 1n410; 4;trägertour 099;1410;autotour 1n410; 5;trägertour 100;1410;autotour 1n410; but if if clause enabled output looks this:
1;trägertour 096;1410;autotour 1n410; 3;trägertour 098;1410;autotour 1n410; 5;trägertour 100;1410;autotour 1n410; so why?
you advance same iterator twice in same iteration of while loop (by calling it2.next() twice). shouldn't.
while(it.hasnext() && it2.hasnext()) { string str = it2.next(); system.out.println(str); if(it.next().getline().contains(str)) { //it.remove(); } }
Comments
Post a Comment