Generics Java Tutorial

import java.util.ArrayList;
public class MainClass {
  public static void main(String args[]) {
    Integer[] integers = { 1, 2, 3, 4, 5 };
    ArrayList integerList = new ArrayList();
    for (Integer element : integers)
      integerList.add(element);
    System.out.printf("integerList contains: %s\n", integerList);
    System.out.printf("Total of the elements in integerList: %.0f\n\n", sum(integerList));
    Double[] doubles = { 1.1, 3.3, 5.5 };
    ArrayList doubleList = new ArrayList();
    for (Double element : doubles)
      doubleList.add(element);
    System.out.printf("doubleList contains: %s\n", doubleList);
    System.out.printf("Total of the elements in doubleList: %.1f\n\n", sum(doubleList));
    Number[] numbers = { 1, 2.4, 3, 4.1 }; // Integers and Doubles
    ArrayList numberList = new ArrayList();
    for (Number element : numbers)
      numberList.add(element);
    System.out.printf("numberList contains: %s\n", numberList);
    System.out.printf("Total of the elements in numberList: %.1f\n", sum(numberList));
  }
  public static double sum(ArrayList list) {
    double total = 0;
    for (Number element : list)
      total += element.doubleValue();
    return total;
  }
}
integerList contains: [1, 2, 3, 4, 5]
Total of the elements in integerList: 15
doubleList contains: [1.1, 3.3, 5.5]
Total of the elements in doubleList: 9.9
numberList contains: [1, 2.4, 3, 4.1]
Total of the elements in numberList: 10.5