-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUseSet.java
More file actions
34 lines (24 loc) · 924 Bytes
/
UseSet.java
File metadata and controls
34 lines (24 loc) · 924 Bytes
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.*;
public class UseSet {
public static void main(String[] argv) throws Exception
{
// Creating object of ArrayList<Integer>
ArrayList<Integer>
arrlist = new ArrayList<Integer>();
// Populating arrlist1
arrlist.add(1);
arrlist.add(2);
arrlist.add(3);
arrlist.add(4);
arrlist.add(5);
// print arrlist
System.out.println("Before operation: " + arrlist);
// Replacing element at the index 3 with 30
// using method set()
int i = arrlist.set(3, 30);
// Print the modified arrlist
System.out.println("After operation: "+ arrlist);
// Print the Replaced element
System.out.println("Replaced element: " + i);
}
}