ArrayList
Basics
After importing the package, I'm creating an arraylist of String type called "math". I'm adding two lists to math, "basic" and "advanced". Basic has the 4 basic math operations (add, subtract, multiply, divide) while advanced has more complex ones such as square roots and exponents. I'm using "math.addAll();" to add both lists to the ArrayList, then printing it as the original.
import java.util.ArrayList; // import package
ArrayList<String> math = new ArrayList<String>(); // new arraylist
List<String> basic = new ArrayList<String>(); // 2 lists to be added to arraylist
List<String> advanced = new ArrayList<String>();
basic.add("addition"); // adding these items to basic list
basic.add("subtraction");
basic.add("multiplication");
basic.add("division");
advanced.add("square root"); // adding to advanced list
advanced.add("exponent");
advanced.add("logarithm");
math.addAll(basic);
math.addAll(advanced); // adding 2 lists to math
System.out.println("Original: " + math); // math has all items from both
math.removeAll(advanced);
System.out.println("Basics: " + math);
Removing the last element (number 3) from the arraylist and printing it
math.remove(3);
System.out.println("Remove last element: " + math);
Removing all items from the array so it is now empty
math.clear();
System.out.println("Cleared: " + math);