previous | start | next

Example (a printArrayList method)

The ArrayList doesn't allow an index (with []), but instead you use the ArrayList Integer get(int i) method for the same purpose - to access the i-th element.

The first element is at i = 0, similar to an ordinary array.

    1     public static void printArrayList(ArrayList<Integer> a)
    2     {
    3       for(int i = 0; i < a.size(); i++) {
    4         System.out.printf("%3d. %d\n", i, a.get(i));
    5       }
    6     }


previous | start | next