javacollectionsguavaapache-commons-collection

Java Composite List


I'm looking for a opensource library that has an implementation of a composite list. I need a list that reads its values from some other lists and can be constructed something like this:

List list1 = new ArrayList();
list1.add("0");
List list2 = new LinkedList();
list2.add("1");
list3.add("2");
List list3 = new CompositeList(list1, list2...)
then:
assertEquals("0", list3.get(0));
assertEquals("1", list3.get(1));
assertEquals("2", list3.get(2));
The idea is that I don't need to copy over everything from the source lists.

A quick google didn't find anything, I didn't see it in Guava or commons collections (I may have overlooked it). I don't really have the time to implement it properly right now.


Solution

  • CompositeCollection from Commons Collections seems to do what you need, even if it's not generified.