The following is an example of an error that is incorrectly specified. How should I fix it and why did I get an error?
Vector <int> vi = new Vector <int> ();
The following is an example of an error that is incorrectly specified. How should I fix it and why did I get an error?
Vector <int> vi = new Vector <int> ();
Java generics don't support primitive types like int
. You can use the java.lang.Integer
wrapper class instead:
Vector <Integer> vi = new Vector<Integer>();
As a side note, while Vector
isn't officially deprecated, it's been considered outdated since JDK 1.2, and you should probably use an ArrayList
instead.