我的主要類代碼數組列表不顯示正確的輸出
{
ArrayList<Item> items = new ArrayList<Item>();
Scanner file = new Scanner(kk.class.getResourceAsStream("product.txt"));
while (file.hasNextLine()) {
String[] sp = file.nextLine().split(",");
// extract item number, description, price and type
itemNum = Integer.parseInt(sp[0]);
des = sp[1];
price = Integer.parseInt(sp[2]);
Item objt = new Item(itemNum, des, price); // Creating a new object
items.add(objt); // Adding it to the list
}
System.out.println(items);
}
輸出我得到
[[email protected],[email protected],[email protected],dada.Item @ 5b4c92a7,[email protected],
我的物品類別代碼
private int itemNum = 0;
private String des = "";
private int price = 0;
public Item(int i, String d, int p) {
itemNum = i;
des = d;
price = p;
}
什麼是應該做你的代碼?你還嘗試過什麼? – PatJ 2015-03-25 00:43:12
我想arrayList存儲我的文本文件中的數據 – 2015-03-25 01:14:35