Reference

Arrays

Declaration

  String peppers[] = new String[3];
  String[] peppers = new String[3];
  String peppers[] = {"chile","green","red"};
  String[] peppers = {"chile","green","red"};

Multidimensional Arrays

To create a two dimensional array of 3 rows by 4 columns,

  double[][] dblMatrix = new double[3][4]

Working with Arrays

To access an entry in an array reference the index of the entry,

  peppers[1]

To obtain the size of an array,

  peppers.length

In the package java.lang.System we have the following useful methods,

Static void arraycopy(Object from, int FromIndex, Object to, int toIndex, int count);

where from is an array of any type, fromIndex starting index of the array to the array to copy to and must be of the same type as the first array, toIndex starting index of where top copy to count number of elements to copy. API

In the package java.util.Arrays we have the following useful methods,

  static void sort(a);
  static int binarySearch(a, v);
  static void fill(a, v);
  static boolean equals(a, b);

where a and b are arrays and v is a value of same type as the array. Refer to the API for further details.