I want to create a list view that consists of the concatenation of a number of other lists.
Example:
List<Integer> l1 = Lists.newArrayList(1);
List<Integer> l2 = Lists.newArrayList(2);
List<Integer> l3 = Lists.newArrayList(3);
// This call should not copy any of the argument lists content
List<Integer> concatenation = new ConcatenationListView(l1, l2, l3);
System.out.println(concatenation); // Prints [1, 2, 3]
l3.add(4);
System.out.println(concatenation); // Prints [1, 2, 3, 4]
What kind of technique and or pattern can I use in Java to fulfill these requirements?
Details
- I want the concatenation to be lazy. (That's the meaning of "view" in this context.)
- I want change to the component lists the reflect on the concatenation. (Also the meaning of "view").
- The view need not to be modifiable.
- This is kind of the opposite of the List.subListmethod.
- It is similar to what the Guava Iterables.concatmethod do, but I need a list as the result, not an iterable.
- My question is similar to this one, but I need a Listas the resulting concatenation, where the poster of the other question is content with anIterableas the result.
 
     
    