Rabbit3cat
02-25-2006, 12:10 PM
I have two lists, one that contains a number of strings and one that is empty. I want to add one of every single element in the first list onto the second list, and where an element occurs more than one time in the first list i want to add it a second time onto the second list.
So that one of every string will be on the second list, and two of every string that appears more than one time on the first list will appear on the second list.
Just to make that more clear, if list 1 contains
[it, is, a, cold, morning, it, it, one, a]
then the second list would contain
[it, is, a, cold, morning, it, one, a]
the third 'it' will not be added
I have a method to add one of every element to the second list:
Iterator iterW = W.iterator();
while ( iterW.hasNext()){
Object e = iterW.next();
if(!check.contains(e)) {
check.add(e);
}
}
I dont know how to add all duplicates just one more time, can anybody help me with this problem?
Thanks
So that one of every string will be on the second list, and two of every string that appears more than one time on the first list will appear on the second list.
Just to make that more clear, if list 1 contains
[it, is, a, cold, morning, it, it, one, a]
then the second list would contain
[it, is, a, cold, morning, it, one, a]
the third 'it' will not be added
I have a method to add one of every element to the second list:
Iterator iterW = W.iterator();
while ( iterW.hasNext()){
Object e = iterW.next();
if(!check.contains(e)) {
check.add(e);
}
}
I dont know how to add all duplicates just one more time, can anybody help me with this problem?
Thanks