I have a custom Class like this:
public class Client {
public int ID;
public String Name;
public double buys;
public double getBuys() {
return this.buys;
}
}
Then, I have defined a list of Client, like:
List<Client> clientList;
Let's say that that List has a lot of client objects, already initialized. How can I map the field "buys" of each client object using Java 8?
I've tried something like:
List<Client> clientList2 = clientList.stream().map(c.getBuys() -> c.getBuys() + 1).collect(Collections.toList());
It, of course, isn't working, but i can't figure out (or find) any way to do it. What I want to do is just to modify every "buys" value of each object of the list. In the example case, I'm adding one, but it could be any operation.
buysfield. What should the output look like?buysfields. Alternatively, If you want to mutate the existing client objects you would useforEachnotmap.