Add () method. Insert data from a location, he has two parameters one parameter is the subscript, and one parameter is the element. It is important to note that the subscript size should be less than or equal to the list collection size, or the subscript out-of-bounds exception will be thrown!
Code: public static void Main (string[] args) {
TODO auto-generated Method Stub
ArrayList list=new ArrayList ();
List.add ("a");
List.add ("B");
List.add ("C");
List.add ("D");
List.add (4, "Z");
SYSTEM.OUT.PRINTLN (list);
}
Operating results: [A, B, C, D, z]
The Remove () method is removed by subscript. It is important to note that the delete operation is not automatically boxed, only the element where the subscript is located is deleted.
Get () method, gets the element at the specified position of the list, and we can iterate through the elements in the collection through Get ().
Code: public static void Main (string[] args) {
TODO auto-generated Method Stub
ArrayList list=new ArrayList ();
List.add ("a");
List.add ("B");
List.add ("C");
List.add ("D");
for (int i=0;i<list.size (); i++) {
System.out.println (List.get (i));
}
}
Operation Result:
A
B
C
D
Set () method to modify the elements of the specified subscript position to other elements.
Several methods of list in Java