So what I'm working on right now should be pretty simple. I'm adding an item to an Arraylist, and if the item's name is equal to the name of another item in the Arraylist, it gets rid of one of the items and just adds the numItem value to the other item. So for example, if a player buys "guns", and the numItem variable is set to 1500, it's added to an arraylist. If they input "guns" again, and that numItem is 2500, I want to get rid of one of the elements in the arrayList and just set the numItem of the remaining to 4000.
public void addItem(Item item)
{
for(int i = 0; i < this.ownedItems.size(); i++)
{
if(item.getName() == this.ownedItems.get(i).getName())
{
item.setNumItem(item.getNumItem() + this.ownedItems.get(i).getNumItem());
this.ownedItems.remove(this.ownedItems.get(i));
}
}
this.ownedItems.add(item);
}