-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMethods.java
71 lines (51 loc) · 2.1 KB
/
Methods.java
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package arrayList;
import java.util.ArrayList;
public class Methods
{
public static void main(String[] args)
{
int count = 0;
ArrayList<String> li = new ArrayList<String>();
ArrayList<String> arr = new ArrayList<String>();
//Adding Elements
li.add("ABC");
arr.add("Ahmad");
arr.add("Alpha");
//Adding Elements Add different Index
li.add(0,"BCD");
//Adding Elements arr list to li list
li.addAll(arr);
//Adding Elements arr list to li list to different index
li.addAll(0,arr);
//Returns the element at the specified position in this list.
System.out.println("Element is "+li.get(2));
//Returns true if this list contains the specified element.
System.out.println(li.contains("ABC"));
//Returns the runtime class of this Object.
System.out.println(li.getClass());
//Returns true if this list contains no elements.
System.out.println(li.isEmpty());
//Replaces the element at the specified position in this list with the specified element.
li.set(0,"XXX");
//Returns the index of the first occurrence of the specified element in this list,
//or -1 if this list does not contain the element.
System.out.println(li.indexOf("BCD"));
//Removes the element at the specified position in this list.Shifts any subsequent
//elements to the left (subtracts one from their indices).
li.remove(3);
//Removes from this list all of its elements that are contained in the specified collection.
li.removeAll(arr);
//Returns the number of elements in this list.
System.out.println("Size is "+li.size());
//Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex,
//exclusive. (If fromIndex and toIndex are equal, the returned list is empty.)
System.out.println(li.subList(0, 2));
//Removes all of the elements from this list. The list will be empty after this call returns.
// li.clear();
for(String obj : li)
{
System.out.println(count+" "+obj);
count++;
}
}
}