The problem with your code is to create only one instance of the Item ( Item item = new Item) object , and the same instance is added to the list again and again.
You need to create a new instance Itemfor each line in the file and add it to the list, as shown below.
Fix:
List<Item> items = new ArrayList<Item>();
String line = null;
while ((line = reader.readLine()) != null) {
String[] split = line.split(",");
Item item = new Item();
item.name = split[0];
item.quantity = Integer.valueOf(split[1]);
item.price = Double.valueOf(split[2]);
item.total = item.quantity * item.price;
items.add(item);
}
source
share