java - Remove NOT duplicated objects from two lists -
well, i've read lot removing duplicated values lists
, nothing maintaining in fact duplicated in list. i'll try explain problem:
i have read values db , save every entry (integer entry) matches searching criterias. operation done n times, since it's loop operation. returning object must list (or arraylist, or whatever list implementation adequate purpose).
to make clear, pseudocode:
for (int i=0; i<nelements; i++) { templist = getentriesfromdb(i); if (i==0) result=templist; else //this should maintain entries in fact duplicated // in both templist , result result = maintainduplicates(result,templist); } retun result;
i know proposals problem. question is, making new loop extracts every single entry lists, create (third!!) temporal list save them there, etc.. aware cause bottleneck in implementation.
any appreciated, in advance.
the key operation here looking each element of 1 list in other. can slow operation. if lists can long, suggest creating hashset workinghash
contains elements of 1 list, , doing retainall(workinghash) on other.
Comments
Post a Comment