Iterating through double collections in Java -


i'm java beginner, please bare possibly silly or trivial questions. have 2 collections (array lists or hashtables) , want compare each , every element of first collection each , every element of second collection. wrote following code, compares element 1 of first collection element 1 of second collection, element 2 of first collection element 2 of second collection, etc., missing of comparisons want make. can please me out?

public class iteratordemo_1 {    public static void main(string args[]) {      // create 2 array lists:     arraylist alletters = new arraylist();     arraylist alnumbers = new arraylist();      // add elements array lists:     alletters.add("c");     alletters.add("b");     alletters.add("z");     alletters.add("x");     alnumbers.add("1");     alnumbers.add("6");     alnumbers.add("3");     alnumbers.add("7");      // use iterator display contents of 'al':     system.out.println("original contents of 'alletters': ");     iterator itrl = alletters.iterator();       system.out.println("original contents of 'alnumbers': ");     iterator itrn = alnumbers.iterator();       while(itrl.hasnext()){           while(itrn.hasnext()){             object elementl = itrl.next();               object elementn = itrn.next();             boolean result = elementl.equals(elementn);             system.out.println(result);             system.out.println(elementl + " ");             system.out.println(elementn + " ");         }     }     system.out.println();   }  } 

while(itrl.hasnext()){       object elementl = itrl.next();      while(itrn.hasnext()){         object elementn = itrn.next();         boolean result = elementl.equals(elementn);         system.out.println(result);         system.out.println(elementl + " ");         system.out.println(elementn + " ");     }     itrn = alnumbers.iterator(); } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -