I am having problems casting an Integer Vector like shown below. Casting the String is ok, but i’m having problems with the Integer.
private Vector a = new Vector();
Record record = new Record();
record.setName((String) listName.elementAt(i));
record.setPrice((int) listPrice.elementAt(index));
a.addElement(record);
Below is the class Record
package goldenicon;
public class Record {
String name;
int price;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}
You can’t put primitive type inside Arraylist or Vectors. You have to use the wrapper classes for such operations, such as
Integerrather thanint, orDoublerather thandouble.Similarly, while retrieving the values from the Vector, you will get the object of Integer and not int.
So you will have to code something like this