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 ]
Muhammad Ijaz wrote:I am sorry
Campbell Ritchie wrote:I thought about deleting it earlier, but left it as not being exactly the same as the final answer.
Muhammad Ijaz wrote:I am sorry Sagar, you are right. I shouldn't give the code...
Same thought here, initially, but the reason to ping is simple, let the user think and use Java API
seetharaman venkatasamy wrote:
Sagar Rohankar wrote: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 ]
It is called Merge Sort
I knew one thing, a sort is different from set intersection.
It is not a way of merging two separate collections.