import java.util.ArrayList; //Suppress Eclipse compiler warnings about unused local variables @SuppressWarnings("unused") public class ArrayListWithoutGenerics { public static void main(String[] args) { // By not using generics, an ArrayList can be created without defining // what type of elements it can contain; this allows elements of // different types to be put into one ArrayList, but it also means // that the elements must be cast into their specific types when they // are retrieved from the ArrayList, since the types of elements being // stored in the ArrayList are not known to the ArrayList itself ArrayList stuff = new ArrayList(); stuff.add("Heather"); stuff.add(37); stuff.add(82.5); stuff.add(false); // Displayed outputs do not need to be cast System.out.println(stuff.get(0)); System.out.println(stuff.get(1)); System.out.println(stuff.get(2)); System.out.println(stuff.get(3)); // Outputs into variables must be cast to avoid syntax errors String name = (String) stuff.get(0); Integer num1 = (Integer) stuff.get(1); Double num2 = (Double) stuff.get(2); Boolean letter = (Boolean) stuff.get(3); } }