June 2018
Beginner
722 pages
18h 47m
English
The void copy(List<T> dest, List<T> src) method copies elements of the src list to the dest list and preserves the element order. This method is very useful in case you need to make one list a sublist of another list:
List<String> list1 = Arrays.asList("s1","s2");List<String> list2 = Arrays.asList("s3", "s4", "s5");Collections.copy(list2, list1);System.out.println(list2); //prints: [s1, s2, "s5"]
While doing this, the copy() method does not consume additional memory - it just copies the values over the already allocated memory. It makes this method helpful for cases where the traditional way of copying lists of equal sizes is not acceptable:
List<String> list1 = Arrays.asList("s1","s2");List<String> list2 = Arrays.asList("s3", "s4" ...
Read now
Unlock full access