I have hashtable consist of 5 key with their corresponding pair values in the form of arraylist. My problem is i want to get common elements between two arraylists. that is common elements between 1 and 2 , common elements between 1,3 , common elements between 1and 4 , common elements between 1and 5. how can do this is. can you give code for this. i'm waiting. can you explain this please.
Muhammad Ijaz wrote:Following is the hint on how to use Set and retainAll method to resolve your problem
Many of us couldn't control ourselves from sharing what we got or our knowledge, but giving code in that way is not a good way. At least let them try, let them come up with their own code/solutions.
seetharaman venkatasamy wrote:use merge sort .
Not exactly a merge sort, but while merging, just checked out the equality for the elements between two sorted halves and add the common element into a result/final list. [Looks like it get finally resulted as my first idea ]
Joined: Mar 03, 2009
I am sorry Sagar, you are right. I shouldn't give the code...
Sorry for not noticing before, but there is a misconception about merge sort. Merge sort is an algorithm which sorts something (not a Set, which has no concept of order) by dividing it into smaller and smaller parts, then merging the parts together.
It is not a way of merging two separate collections.