previous | start | next

The length member

The number of elements that an array can hold is stored by an array and can be accessed.

    public void static main(String[] args)
    {
      String[] str = new String[5];

      str[0] = "one";
      str[1] = "two";
      str[2] = "three";
      str[3] = "four";
      str[4] = "five";

      // str.length is 5

      for(int i = 0; i < str.length; i++) {
         System.out.println(str[i]);
      }
   


previous | start | next