Conditions: do not modifiy the original lists; JDK only, no external libraries. Bonus points for a one-liner or a JDK 1.3 version.
Is there a simpler way than:
List<String> newList = new ArrayList<String>();
newList.addAll(listOne);
newList.addAll(listTwo);
In Java 8:
This is simple and just one line, but will add the contents of listTwo to listOne. Do you really need to put the contents in a third list?
Slightly simpler:
The smartest in my opinion:
If you want to do this statically you can the following.
The examples uses 2 EnumSets in natural-order (==Enum-order)
A, B
and joins then in anALL
list.No way near one-liner, but I think this is the simplest: