Insert multiple values in hashSet Java

Viewed 43

The idea is to set different values from one class to another using the interface.

My code:

public Make(String name, int foundingYear, String founder) {
    this.name = name;
    this.foundingYear = foundingYear;
    this.founder = founder;
}
//other code

So I want to set those values in another class like this:

public record anotherClass (String name, String color, int hp) {

Make make = new Make();
Set<Make> makes = new HashSet<>();
makes.add("name", 1995, "founder");

The thing is when I'm trying to add values (makes.add("name", 1995, "founder");) I can't do that, because it expects just one argument to be added of type makes. What I'm I doing wrong?

1 Answers

You must instantiate Make using the 3 params, then add this make into the Set. See below:

Make make = new Make("name", 1995, "founder"); // use this make
Set<Make> makes = new HashSet<>();
makes.add(make);
Related