algorithm - Java build List from values of multiple Maps in a particular order -
suppose have list of integers in meaningful order (list1).
you have 2 map's integer keys subset of list1. there no overlap between 2 maps, between them both may possible list1 proper superset of set of both of keysets (i.e., there integers in list1 missing both maps).
how can build new list of objects 2 maps in objects appear in order integer key appears in list1?
you can loop:
map map1; map map2; list list2; // iterate through of possible keys in order for(object possiblekey: list1) { // if possible ke key in 1 of maps, // add new list. preserve order. if(map1.containskey(possiblekey)) list2.add(map1.get(possiblekey)); else if (map2.containskey(possiblekey)) list2.add(map2.get(possiblekey)); }
the above code simplified, should general idea.
Comments
Post a Comment