Skip to content
Advertisement

How to search in arrayList then change?

So i’m making a supermarket program that allows to add products and sell them, so far i have this:

JavaScript

I´d like to know how to search in Product list by name and then change the stock(subtract-n) to sell n of that product.

Advertisement

Answer

You can use Stream API to find out the product by name. Filter the list by checking the name of product and get first match.

JavaScript

Then can check is product found then update the stock

JavaScript

Suggestion to use getter/setter for fields.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement