// Importing
import java.util.ArrayList;

// Creating an ArrayList
ArrayList<String> array = new ArrayList<>();
array.add("aa");
array.add("bb");
array.add("dd");
array.add("ii");
System.out.println(array);
[aa, bb, dd, ii]
ArrayList<String> array1 = new ArrayList<>();
array1.add("ee");
array1.add("ff");
array1.add("ff");
array1.add("gg");
array1.add("hh");
System.out.println(array1);
[ee, ff, ff, gg, hh]
// add(int index, element)
array.add(2, "cc");
System.out.println(array);
[aa, bb, cc, dd, ii]
// addAll(int index, Collection collection)
array.addAll(4, array1);
System.out.println(array);
[aa, bb, cc, dd, ee, ff, ff, gg, hh, ii]
// size()
array.size();
10
// clear()
array1.clear();
System.out.println(array1);
[]
// remove(int index)
array.remove(6);
System.out.println(array);
[aa, bb, cc, dd, ee, ff, gg, hh, ii]
// remove(element)
array.remove("ii");
System.out.println(array);
[aa, bb, cc, dd, ee, ff, gg, hh]
// get(int index)
array.get(5);
ff
// set(int index, element)
array.set(5, "dd");
System.out.println(array);
[aa, bb, cc, dd, ee, dd, gg, hh]
// indexOf(element)
array.indexOf("dd");
3
array.indexOf("ff");
-1
// lastIndexOf(element)
array.lastIndexOf("dd");
5
array.lastIndexOf("ii")
-1
// equals(element)
array.equals(array1);
false
ArrayList<String> equal = new ArrayList<>(Arrays.asList("aa", "bb", "cc", "dd", "ee", "dd", "gg", "hh"));
array.equals(equal);
true
// hashCode()
array.hashCode();
-152662207
// isEmpty()
array.isEmpty();
false
array1.isEmpty();
true
// contains(element)
array.contains("bb");
true
array.contains("kk");
false
ArrayList<String> contain = new ArrayList<>(Arrays.asList("bb", "cc", "dd", "ee", "gg"));
// containsAll(Collection collection)
array.containsAll(contain);
true
contain.add("jj");
array.containsAll(contain);
false
// sort(Comparator comp)
array.add("1");
array.add("10000");
array.sort(Comparator.naturalOrder());
System.out.println(array);
[1, 10000, aa, bb, cc, dd, dd, ee, gg, hh]
array.set(4, "9eji");
array.set(8, "z8f");
array.add("9f8");
array.add("y8de1");
array.add("08de1");
array.sort(Comparator.reverseOrder());
System.out.println(array);
[z8f, y8de1, hh, ee, dd, dd, bb, aa, 9f8, 9eji, 10000, 1, 08de1]