0

I am trying to do the following:

ArrayList<String>[] names = new ArrayList<>()[];

But NetBeans shows Illegal start of expression. Can it be solved without changing to String[][] or ArrayList<ArrayList<String>>?

shmosel
  • 42,915
  • 5
  • 56
  • 120
bieito98
  • 11
  • 2
  • Maybe you want `ArrayList`, i.e. a list of String arrays. – Juan Carlos Mendoza Oct 19 '17 at 16:38
  • 3
    You can't create an array of parameterized types in Java. – wkl Oct 19 '17 at 16:41
  • 1
    You can kinda-sorta fake it with something like `ArrayList[] names = new ArrayList[size];`, but you really shouldn't mix arrays and generics. There's a reason the compiler will give you an unchecked conversion warning if you try that sort of thing. – azurefrog Oct 19 '17 at 16:44
  • 1
    An array has a fixed length which must be defined when it is created. For example, `new int[]` is illegal, but `new int[5]` is legal. – VGR Oct 19 '17 at 16:44

0 Answers0