-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayListExample.java
More file actions
47 lines (33 loc) · 1.03 KB
/
ArrayListExample.java
File metadata and controls
47 lines (33 loc) · 1.03 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.yashas;
import java.util.ArrayList;
import java.util.Scanner;
public class ArrayListExample {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
//syntax
ArrayList<Integer> list = new ArrayList<>(5);
/*list.add(3);
list.add(45);
list.add(23);
list.add(56);
list.add(90); //6 input
// checking
System.out.println(list.contains(45));
System.out.println(list.contains(99));
System.out.println(list);
// update
list.set(0,99);// list.set(index no., no. we want)
System.out.println(list);
// remove
list.remove(2);
System.out.println(list);
*/
for(int i=0;i<5;i++){
list.add(in.nextInt());
}
for(int i=0;i<5;i++){
System.out.println(list.get(i)); // pass index here,list[index] systax will not possible
}
//System.out.println(list);
}
}