-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC52_CopyArrayList.java
More file actions
30 lines (23 loc) · 1.04 KB
/
C52_CopyArrayList.java
File metadata and controls
30 lines (23 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 45. Write a Java program to copy one ArrayList into another.
import java.util.ArrayList;
import java.util.Collections;
public class C52_CopyArrayList {
public static void main(String[] args) {
Name.info(); // Print name and enrollment number
// Source ArrayList
ArrayList<String> sourceList = new ArrayList<>();
sourceList.add("Red");
sourceList.add("Green");
sourceList.add("Blue");
// Destination ArrayList (should be at least the same size as sourceList)
ArrayList<String> destinationList = new ArrayList<>();
destinationList.add("White");
destinationList.add("Black");
destinationList.add("Gray");
System.out.println("Source List: " + sourceList);
System.out.println("Destination List (before copy): " + destinationList);
// Copy sourceList into destinationList
Collections.copy(destinationList, sourceList);
System.out.println("Destination List (after copy): " + destinationList);
}
}