MCPcopy Create free account
hub / github.com/Manvityagi/PW-Skills-Java-Course-Codes / main

Method main

Lecture 24 - Arraylist/src/Main.java:4–63  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

2
3public class Main {
4 public static void main(String[] args) {
5 //wrapper classes
6// Integer in = Integer.valueOf(4);
7// System.out.println(in);
8// Float f = Float.valueOf(4.5f);
9// System.out.println(f);
10
11 ArrayList<Integer> l1 = new ArrayList<>();
12
13 // add new element
14
15 l1.add(5); // 5
16 l1.add(6); // 5 6
17 l1.add(7); // 5 6 7
18 l1.add(8); // 5 6 7 8
19
20 // get an element at index i
21// System.out.println(l1.get(1)); // 6
22
23
24// // print with for loop
25// for(int i = 0; i < l1.size(); i++){
26// System.out.println(l1.get(i)); // 5, 6, 7, 8
27// }
28
29 //printing the array list directly
30 System.out.println(l1); // [5, 6, 7, 8]
31
32 //adding element at some index i
33 l1.add(1, 100);
34 System.out.println(l1); // [5 100 6 7 8]
35
36
37 //modifying element at index i
38 l1.set(1, 10);
39 System.out.println(l1); // [5, 10, 6, 7, 8]
40
41
42 //removing an element at index i
43 l1.remove(1);
44 System.out.println(l1); // 5, 6, 7, 8
45
46
47 //removing an element e
48 l1.remove(Integer.valueOf(7));
49 System.out.println(l1); // 5, 6, 8
50
51 //checking if an element exists
52 boolean ans = l1.contains(Integer.valueOf(60));
53 System.out.println(ans);
54
55 // if you don't specify class, you can put anything inside l
56 ArrayList l = new ArrayList();
57 l.add("pqres");
58 l.add(1);
59 l.add(true);
60 System.out.println(l);
61

Callers

nothing calls this directly

Calls 1

addMethod · 0.45

Tested by

no test coverage detected