forked from jvm-coder/Java_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayList.java
More file actions
27 lines (25 loc) · 690 Bytes
/
Copy pathArrayList.java
File metadata and controls
27 lines (25 loc) · 690 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
import java.util.*;
public class ArrayList
{
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
// creating a ArrayList object
ArrayList<Integer> arr = new ArrayList<Integer>();
int n=10;
for(int i=0;i<=5;i++){
// add element and taking input
arr.add(sc.nextInt());
}
//print all elememt
System.out.println(arr);
//remove the 4th index elemet
arr.remove(4);
System.out.println(arr);
//acessing the element by index -->method get(i)
System.out.println(arr.get(2));
//To print the elements or ArrayList.(enhanced loop is used)
for(int element : arr){
System.out.println(element);
}
}
}