If you're using Java 8, you can create a new list using the same objects as the previous one simply using streams:
List<Double> secondList = firstList.stream().collect(Collectors.toList());
If you want a new list that doesn't share the same objects with the first one, you can do this (supposing your objects implements Cloneable
):
If you're using Java 8, you can create a new list using the same objects as the previous one simply using streams:
List<Double> secondList = firstList.stream().collect(Collectors.toList());
If you want a new list that doesn't share the same objects with the first one, you can do this (supposing your objects implements Cloneable
):
List<Double> secondList = firstList.stream().map(v -> v.clone()).collect(Collectors.toList());