5 Replies Latest reply: Nov 13, 2007 7:54 PM by 807600 RSS

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

    807600
      Hello,

      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!