on 09-22-2006 11:04 AM
with different length?
Imagine you´ve got one ParentArrayList, which contains one or more ArrayLists as elements. The (Child)ArrayLists contains multiple String elements of different size.
Here is a small Graphic on this:
Parent_ArrayList
#
#
####Child_ArrayList_1->element1->element2->element3
#
#
####Child_ArrayList_2->element1->....elementn
#
#
####Child_ArrayList_n->element1->element2->element3
E.g.:I have to compare all the elements of the child_arraylists_1 with child_arraylists_2 , write all elements which are euqal into an other temparrayList.Then Compare temp arraylist with elements of Child_ArrayList_n and write it back into the temp_arraylist.
I hope I could explain my problem?!?
Thank you for any suggestions?!
Hi Mehmet,
private final static String[][] initial_data = {{"1", "2", "3", "5"},
{"2", "3", "5", "8", "12"},
{"3", "5", "7", "12", "20"},
{"4", "7", "3", "9", "5", "2"},
{"5", "9", "2", "7", "9", "0", "3"}};
private final static List Parent_ArrayList = new ArrayList();
static {
for (int i = 0; i < initial_data.length; i++) {
final List Child_ArrayList = new ArrayList();
for (int j = 0; j < initial_data<i>.length; j++) {
Child_ArrayList.add(initial_data<i>[j]);
}
Parent_ArrayList.add( Child_ArrayList );
}
}
Set common = null;
for (Iterator iter = Parent_ArrayList.iterator(); iter.hasNext();) {
List element = (List) iter.next();
Set tempSet = new HashSet(element);
if(null==common) {
common = tempSet;
} else {
common.retainAll(tempSet);
}
}
common will contain common string from all children.
Best regards, Maksim Rashchynski.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.