0

I have 6 list of Objects in Java with a data structure like this:

Class MyObj {
    int identifier;
    Class someOtherClass;
}

Every List in the 6 Lists is a List<MyObj>.

I want to build a final list which does merge sort while reading all the 6 lists and prepare a final list.

I believe Merge Sort or similar solution is the way to go. I looked at comparator example as well but could not find one matching my requirements. Can someone suggest a library or existing API that can help me accomplish this task?

I also found a solution at How to Sort a List<T> by a property in the object but it does inArray sort, it does not tke account of multiple Lists.

All 6 Lists are already Sorted, I need combined sorted List

Community
  • 1
  • 1
CodeMonkey
  • 2,265
  • 9
  • 48
  • 94
  • Are your 6 lists already sorted? If not, you might as well combine into one list before using a normal sort. – searlea Apr 29 '17 at 10:52
  • @searlea they are already sorted, that's why I was thinking of a solution like MergeSort. – CodeMonkey Apr 29 '17 at 10:56
  • Did you see this: http://stackoverflow.com/a/1775748/98493 ? – searlea Apr 29 '17 at 11:01
  • Just concatenate the 6 lists and sort the resulting list. Only optimize if you really have a performance problem. – JB Nizet Apr 29 '17 at 11:16
  • @JBNizet the list is huge, it will have 1000's of elements. – CodeMonkey Apr 29 '17 at 11:20
  • Sorting the concatenation of 6 sorted lists of 10,000 random integers takes 9 milliseconds on my machine. Is that worth optimizing? Measure before optimizing. Computers are fast. – JB Nizet Apr 29 '17 at 11:48

0 Answers0