Arrays of Objects

Contact Us or call 1-877-932-8228
Arrays of Objects

Arrays of Objects

If an array contains objects, those objects' properties and methods may be accessed.

The notation uses the array variable name, the index in brackets, a dot, and the property or method.

Code Sample:

Java-Arrays/Demos/Arrays2.java
public class Arrays2 {
  public static void main(String[] args) {
    String[] names = new String[3];
    names[0] = "Joe";
    names[1] = "Jane";
    names[2] = "Herkimer";
    printArray(names);
  }
  public static void printArray(String[] data) {
    for (int i = 0; i < data.length; i++) {
      System.out.println(data[i].toUpperCase());
    }
  }
}
Next