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:
You could do it with a static import and a helper class
nb the generification of this class could probably be improved
public class Lists {
private Lists() { } // can't be instantiated
public static List join(List... lists) {
List result = new ArrayList();
for(List list : lists) {
result.addAll(list);
}
return results;
}
}
Then you can do things like
import static Lists.join;
List result = join(list1, list2, list3, list4);