Merge pull request #10210 from vishal1023/BAEL-4236

Bael 4236
This commit is contained in:
Greg
2020-11-08 13:41:04 -05:00
committed by GitHub
10 changed files with 172 additions and 0 deletions
@@ -0,0 +1,14 @@
package com.baeldung.exception.indexoutofbounds;
import java.util.ArrayList;
import java.util.List;
public class CopyListUsingAddAllMethodDemo {
static List<Integer> copyList(List<Integer> source) {
List<Integer> destination = new ArrayList<>();
destination.addAll(source);
return destination;
}
}
@@ -0,0 +1,10 @@
package com.baeldung.exception.indexoutofbounds;
import java.util.Collections;
import java.util.List;
public class CopyListUsingCollectionsCopyMethodDemo {
static void copyList(List<Integer> source, List<Integer> destination) {
Collections.copy(destination, source);
}
}
@@ -0,0 +1,10 @@
package com.baeldung.exception.indexoutofbounds;
import java.util.ArrayList;
import java.util.List;
public class CopyListUsingConstructorDemo {
static List<Integer> copyList(List<Integer> source) {
return new ArrayList<>(source);
}
}
@@ -0,0 +1,12 @@
package com.baeldung.exception.indexoutofbounds;
import java.util.List;
import java.util.stream.Collectors;
public class CopyListUsingJava8StreamDemo {
static List<Integer> copyList(List<Integer> source) {
return source
.stream()
.collect(Collectors.toList());
}
}
@@ -0,0 +1,13 @@
package com.baeldung.exception.indexoutofbounds;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class IndexOutOfBoundsExceptionDemo {
static List<Integer> copyList(List<Integer> source) {
List<Integer> destination = new ArrayList<>(source.size());
Collections.copy(destination, source);
return destination;
}
}