ベクターが重複している理由を知りたいのですが? ArrayList を使用できることはわかっていますが、これは現時点でベクターのみを使用する私の blackberry アプリのテストです。これは私が得続けている結果です:
ID:3 and Name:Catty and Price:100 and Msg:Catty is a preety girl
ID:3 and Name:Catty and Price:100 and Msg:Catty is a preety girl
ID:3 and Name:Catty and Price:100 and Msg:Catty is a preety girl
これがコードです、testapp.java
package testing;
import java.util.Vector;
public class testapp {
private static Vector<String> listElements= new Vector<String>();
private static Vector<String> listName= new Vector<String>();
private static Vector<Integer> listPrice= new Vector<Integer>();
private static Vector<String> listDate= new Vector<String>();
private static Vector<String> listAbstract= new Vector<String>();
private static Vector<rec> a = new Vector<rec>();
static rec record = new rec();
public static void main(String[] args){
vectorBuilder();
recordBuilder();
showElements();
}
public static void recordBuilder(){
try{
for(int i=0;i<listElements.size();i++){
record.setId((String) listElements.elementAt(i));
record.setName((String) listName.elementAt(i));
record.setDate((String) listDate.elementAt(i));
record.setPrice(((Integer) listPrice.elementAt(i)).intValue());
record.setAbstract((String) listAbstract.elementAt(i));
a.addElement(record);
}
}catch (Exception e){
System.out.println("Record Builder Error: " + e.getMessage());
}
}
public static void vectorBuilder(){
//Ben
listElements.addElement("1");
listName.addElement("Ben");
listPrice.addElement(502);
listDate.addElement("2012-05-12");
listAbstract.addElement("Ben is a Good Boy");
//Kesha
listElements.addElement("2");
listName.addElement("Kesha");
listPrice.addElement(367);
listDate.addElement("2012-02-24");
listAbstract.addElement("Kesha Works hard in her school work");
//Catty
listElements.addElement("3");
listName.addElement("Catty");
listPrice.addElement(100);
listDate.addElement("2012-01-04");
listAbstract.addElement("Catty is a preety girl");
}
public static void showElements(){
for(int i=0;i<a.size();i++)
{
rec r = (rec) a.elementAt(i);
System.out.println("ID:"+r.getId()+" and Name:"+r.getName()+" and Price:"+r.getPrice()+" and Msg:"+r.getAbstract());
}
}
}
ここにrec.javaがあります
package testing;
public class rec {
String name;
String id;
String date;
String strAbstract;
int price;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getAbstract() {
return strAbstract;
}
public void setAbstract(String strAbstract) {
this.strAbstract = strAbstract;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}