M
Matteo
I had the following snippet of code using array of vectors:
Vector[] tmpArr = new Vector[n];
for(int j=0; j<nCol; j++)
{
tmpArr[j] = new Vector();
....
str = ...
....
if (!tmpArr[j].contains(str))
tmpArr[j].add(str);
}
And I want to convert to generics:
Vector<String>[] tmpArr = new Vector<String>[n];
for(int j=0; j<n; j++)
{
tmpArr[j] = new Vector<String>();
....
String str = ....
....
if (!tmpArr[j].contains(str))
tmpArr[j].add(str);
}
But the first row gives me an error:
If I change it in
Vector<String>[] tmpArr = new Vector<String>[n];
(as I've seen in a pdf by G.Bracha talking aout collections)
it gemves me an error
tmpArr[j].add(str);
row.
The only way it seems to work is
Vector<String>[] tmpArr = new Vector[n];
but it gives me the unchecked conversion warning.
How can I create an array of generics?
Thank you!
for(int j=0; j<n; j++)
{
tmpArr[j] = new Vector<String>();
....
String str = ....
....
if (!tmpArr[j].contains(str))
tmpArr[j].add(str);
}
Vector[] tmpArr = new Vector[n];
for(int j=0; j<nCol; j++)
{
tmpArr[j] = new Vector();
....
str = ...
....
if (!tmpArr[j].contains(str))
tmpArr[j].add(str);
}
And I want to convert to generics:
Vector<String>[] tmpArr = new Vector<String>[n];
for(int j=0; j<n; j++)
{
tmpArr[j] = new Vector<String>();
....
String str = ....
....
if (!tmpArr[j].contains(str))
tmpArr[j].add(str);
}
But the first row gives me an error:
Generic array creation.
If I change it in
Vector<String>[] tmpArr = new Vector<String>[n];
(as I've seen in a pdf by G.Bracha talking aout collections)
it gemves me an error
in thecannot find symbol
method add(String)
tmpArr[j].add(str);
row.
The only way it seems to work is
Vector<String>[] tmpArr = new Vector[n];
but it gives me the unchecked conversion warning.
How can I create an array of generics?
Thank you!
for(int j=0; j<n; j++)
{
tmpArr[j] = new Vector<String>();
....
String str = ....
....
if (!tmpArr[j].contains(str))
tmpArr[j].add(str);
}