5 Replies Latest reply on Nov 14, 2007 1:54 AM by 807600

    How to add an element to an array without specifying index?


      I would like to know how to add elements to an array of a specified size without specifying their indices. For example,
      int[] newArr = new int[5];
      newArr[] = 4;
      newArr[] = 6;
      This means I want newArr to look like this:
      [4][6][ ][ ][ ]
      This does not work, even though it does in other languages such as PHP. Can anyone tell me how to do this in Java? I would appreciate it!