-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharrayList.java
More file actions
40 lines (29 loc) · 1 KB
/
arrayList.java
File metadata and controls
40 lines (29 loc) · 1 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
package src;
import java.util.ArrayList;
public class arrayList
{
public static void main(String[] args)
{
ArrayList<Integer> myIntList = new ArrayList<>(3);
// Adding the elements of src.array list
myIntList.add(3);
myIntList.add(2);
myIntList.add(89);
myIntList.add(19);
myIntList.add(92);
// Check whether 32 is in arraylist
System.out.println(myIntList.contains(32));
// Return value at given index
System.out.println(myIntList.get(1));
// For each loop on arraylist using method reference
myIntList.forEach(System.out::println);
// Return boolean whether the list is empty or not.
System.out.println(myIntList.isEmpty());
// Return the size of src.array list
System.out.println(myIntList.size());
// Convert to string Object.
System.out.println(myIntList.toString());
// Clear the src.array list
myIntList.clear();
}
}