forked from Haresh1204/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataManipulation.java
34 lines (27 loc) · 1.02 KB
/
dataManipulation.java
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
31
32
33
34
import java.util.Collections;
import java.util.ArrayList;
class Main {
public static void main(String[] args) {
// Creating an ArrayList
ArrayList<Integer> numbers = new ArrayList<>();
numbers.add(1);
numbers.add(2);
System.out.println("ArrayList1: " + numbers);
// Using reverse()
Collections.reverse(numbers);
System.out.println("Reversed ArrayList1: " + numbers);
// Using swap()
Collections.swap(numbers, 0, 1);
System.out.println("ArrayList1 using swap(): " + numbers);
ArrayList<Integer> newNumbers = new ArrayList<>();
// Using addAll
newNumbers.addAll(numbers);
System.out.println("ArrayList2 using addAll(): " + newNumbers);
// Using fill()
Collections.fill(numbers, 0);
System.out.println("ArrayList1 using fill(): " + numbers);
// Using copy()
Collections.copy(newNumbers, numbers);
System.out.println("ArrayList2 using copy(): " + newNumbers);
}
}