Suppose I refer in my class to a model that contains some kind of data. After I have accessed a particular variable, let's say I want the .add(); method .add(); add these values ​​to the object. What if I need to add multiple values ​​to the object? We'll have to create several times .add(); , turning every time to get/set'ру in the model?

Perhaps the question is not quite correctly formulated, I apologize in advance and is also open to any amendments.

  • What data types do you add? - Senior Pomidor
  • one
    loop in the loop by calling the add method, or create the addAll method (Collection <T> data). If the methods are different, then you have to call each time, or create a method that takes a collection of values ​​and calls those same methods - Artem Konovalov

1 answer 1

You can write this method:

 public void add(String... strings){ list.addAll(Arrays.asList(strings)); //например добавить всё в лист } 

And give the method at least how many arguments, separated by commas.