Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java type safety warning

I'm trying to make an array of vectors like this:

Vector<String>[] wordList = new Vector[29];
for (int i = 0; i < wordList.length; i++) {
  wordList[i] = new Vector<String>(100);
}

But Java warns me that "new Vector[29]" violates type safety. How do I get rid of the the warning?

Update: I've tried:

        wordList = new Vector<String>[29];

Of course, but this generates the error: Cannot create a generic array of Vector

like image 725
Jeremy Avatar asked Aug 07 '26 14:08

Jeremy


2 Answers

Vector<String>[] wordList = (Vector<String>[])new Vector[29];
like image 50
Foo Bah Avatar answered Aug 10 '26 14:08

Foo Bah


Consider using a List of List<String> instead of an array of Vectors, like so:

List<List<String>> wordList = new Vector<List<String>>();

This doesn't generate any warnings.

like image 34
David Avatar answered Aug 10 '26 14:08

David