Apache collections supports collate method since version 4; you can do this using the collate
method in:
org.apache.commons.collections4.CollectionUtils
Here quote from javadoc:
collate(Iterable extends O> a, Iterable extends O> b, Comparator super O> c)
Merges two sorted Collections, a
and b
, into a single,
sorted List such that the ordering of the elements according to
Comparator c is retained.
Do not re-invent the wheel! Document reference:
http://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/CollectionUtils.html