Question: Why can't I create an array of List ?

```
List<String>[] nav = new List<String>[] { new ArrayList<String>() };

```

Eclipse says "Cannot create a generic array of List"

or

```
ArrayList<String>[] nav = new ArrayList<String>[] { new ArrayList<String>() };

```

Eclipse says "Cannot create a generic array of ArrayList"

or

```
List<String>[] getListsOfStrings() {
    List<String> groupA = new ArrayList<String>();
    List<String> groupB = new ArrayList<String>();
    return new List<String>[] { groupA, groupB };
}

```

But I can do this:

```
List[] getLists() {
    return new List[] { new ArrayList(), new ArrayList() };
}

```

Eclipse says that List and ArrayList are *raw types* but it compiles...

Seems pretty simple, why won't it work?

Answer: 
You can't create arrays of generic types, generally.

The reason is that the JVM has no way to check that only the right objects are put into it (with ArrayStoreExceptions), since the difference between `List<String>` and `List<Integer>` are nonexistent at runtime.

Of course, you can trick the compiler by using the raw type `List` or the unbound wildcard type `List<?>`, and then cast it (with a unchecked cast) to `List<String>`. But then it is your responsibility to put only `List<String>` in it and no other lists.
Another solution is to extend `LinkedList<String>` (or `ArrayList<String>`, etc.), then create an array of the subclass.

```
private static class StringList extends LinkedList<String> {}

public static void main(String[] args)
{
    StringList[] strings = new StringList[2];
    strings[0] = new StringList();
    strings[1] = new StringList();
    strings[0].add("Test 1");
    strings[0].add("Test 2");
    strings[1].add("Test 3");
    strings[1].add("Test 4");
    System.out.println(strings[0]);
    System.out.println(strings[1]);
}

```