12 Replies Latest reply: Jun 21, 2007 2:57 AM by 800322 RSS

    int Array's and variable length

      for Strings i simply do:
      String datanames[] = {};
      ArrayList aList = new ArrayList(Arrays.asList(datanames));
      datanames = (String[]) aList.toArray(new String[aList.size()]);
      However the same can't be done with int's because an ArrayList cannot store int's and as a result i need a reference back to the original int array, much like the string example above.

      public class testing {
            * @param args
           public static void main(String[] args) {
                // TODO Auto-generated method stub
                int datavalues[] = {};
                datavalues[datavalues.length] = 1;
      Obviously, with the above i get index out of bounds simply because datavalues hasn't been initialized.

      Quite simply put: i need a way of appending an int array with defining the length.

      Any ideas?

      Message was edited by: