sBarang.add("")will not work. Your attempt to add Stringto a list containing only objects Item.
The second half of your message sounds like you're looking for a more efficient way to assign values to the fields of your instance Item. Do this by adding a constructor to your class. It will look like this:
public class Item {
public Item (String startCode, String startName, int startQty) {
this.code = startCode;
this.name = startName;
this.qty = startQty;
}
...
}
Initialize your element as follows: Item myItem = new Item("101", "Hammer", 10);
Add it to your list as follows: sBarang.add(myItem);
Or use single line: sBarang.add(new Item("101", "Hammer", 10));
source
share