Is there a way to combine the two lists as short as possible with JDK without touching the existing list and without using other libraries?
List<String> newList = new ArrayList<String>();
newList.addAll(listOne);
newList.addAll(listTwo);
I wish it was simpler than this sauce.
list java jdk1.5
The shortest code that I can squeeze out of my head is
List<String> newList = new ArrayList<String>(listOne);
newList.addAll(listTwo);
And if you use another library, use the Apache Commons library and ListUtils.union(list1,list2); You could do this.
© 2024 OneMinuteCode. All rights reserved.