how to copy a list in java code example

Example 1: java copy list

List<Object> copy = new ArrayList<>();
copy.addAll(originalList);

Example 2: java copy list

List<Object> copy = new ArrayList<>(original_list);

Example 3: how to copy list item to another list in java

List<Integer> source = Arrays.asList(1,2,3);
List<Integer> dest = Arrays.asList(4,5,6);
Collections.copy(dest, source);

Example 4: how to copy list item to another list in java

List<Integer> copy = new ArrayList<>();
copy.addAll(list);

Tags:

Java Example