Arrays and Lists.
Self-explanatory
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> ints1 = new ArrayList<Integer>();
ArrayList<Integer> ints2 = new ArrayList<Integer>();
ints2.add(0, -1);
ints2.add(0, -2);
ints2.add(0, -3);
ints2.add(0, -4);
ints2.add(0, -5);
// Add an item:
System.out.println("Add an item:");
System.out.println(ints1);
ints1.add(0, 1);
System.out.println(ints1);
System.out.println("");
// Add items from another list:
System.out.println("Add items from another list:");
System.out.println(ints1);
ints1.addAll(0, ints2);
System.out.println(ints1);
System.out.println("");
// Get size of array:
System.out.println("Get size of array:");
System.out.println(ints1.size());
System.out.println("");
// This method is used to remove all the elements in the list:
System.out.println("This method is used to remove all the elements in the list");
System.out.println(ints1);
ints1.clear();
System.out.println(ints1);
System.out.println("");
ints1.add(0, 1);
ints1.add(0, 2);
ints1.add(0, 3);
ints1.add(0, 4);
ints1.add(0, 5);
// This method removes an element from the specified index:
System.out.println("This method removes an element from the specified index:");
System.out.println(ints1);
ints1.remove(1);
System.out.println(ints1);
System.out.println("");
// This method is used to remove the first occurrence of the given element in the list
System.out.println("This method removes an element from the specified index:");
System.out.println(ints1);
ints1.remove(0);
System.out.println(ints1);
System.out.println("");
}
}
Main.main(null);