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);
Probably not simpler, but intriguing and ugly:
Don't use it in production code... ;)
I'm not claiming that it's simple, but you mentioned bonus for one-liners ;-)
Use a Helper class.
I suggest:
I can't improve on the two-liner in the general case without introducing your own utility method, but if you do have lists of Strings and you're willing to assume those Strings don't contain commas, you can pull this long one-liner:
If you drop the generics, this should be JDK 1.4 compliant (though I haven't tested that). Also not recommended for production code ;-)
A little shorter would be:
You can do a oneliner if the target list is predeclared.