1

I am working in Java and would like to know what adding the brackets does. I looked this up and read through the List documentation but couldn't seem to figure it out.

Ayman Elmubark
  • 717
  • 1
  • 5
  • 10

1 Answers1

10

List<String> is a List of Strings (i.e. a List containing String elements).

List<String>[] is an array of Lists of Strings (i.e. an array whose elements are List<String>.

For every type x, x[] is an array of elements of type x.

Eran
  • 359,724
  • 45
  • 626
  • 694
  • Thanks. I realized this immediately after asking the question. – Ayman Elmubark May 07 '15 at 07:58
  • I'd like to ask how is this used. I can declare the array of lists without a problem, however, I cannot seem to initialize it. I receive an error that I cannot create an array of type generic. If that is the case how can an array of lists be used? – Ayman Elmubark May 07 '15 at 08:13
  • @AymanElmubark You can read about it [here](http://stackoverflow.com/questions/217065/cannot-create-an-array-of-linkedlists-in-java). – Eran May 07 '15 at 08:17