+ Reply to Thread
Results 1 to 2 of 2

Thread: Java ArrayList of Arrays?

  1. #1
    Junior Member
    Join Date
    Jun 2012

    Java ArrayList of Arrays?

    I want to create a mutli dimensional array without a fixed size.

    I need to be able to add items of String[2] to it.

    I have tried looking at:

    private ArrayList<String[]> action = new ArrayList<String[2]>();
    but that doesn't work. does anyone have any other ideas?

  2. #2
    Junior Member
    Join Date
    Jul 2012
    Should be
    private ArrayList<String[]> action = new ArrayList<String[]>();
    action.add(new String[2]);
    You can't specify the size of the array within the generic parameter, only add arrays of specific size to the list later. This also means that the compiler can't guarantee that all sub-arrays be of the same size, it must be ensured by you.

    A better solution might be to encapsulate this within a class, where you can ensure the uniform size of the arrays as a type invariant.

+ Reply to Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts