I have the following InventoryItem class:
@AllArgsConstructor
@Getter
public class InventoryItem {
private String name;
private int amount;
// other properties, getters, etc.
}
And I have an Inventory object that contains a List of InventoryItems.
I want to obtain the amount of the item where the name is equal to the given name.
I am trying to use streams for that purpose:
inventoryItems.stream().filter(item -> item.getName().equals(name));
But it is returning the whole item, I only want the amount. How can I do that?
I am new to java so do not have idea.