Add values from basic array to Set<String>

user1604294 :
  private Set<String> fields = new HashSet<>();

  public void fields(String... s){
    this.fields.addAll(s);
  }

Doesn't compile, saying that:

addAll
(java.util.Collection<? extends java.lang.String>)
in Set cannot be applied
to
(java.lang.String[])

is there is a good way to get around this?

siyopao :

I think you can convert your array to a list first. Maybe something like

this.fields.addAll(Arrays.asList(s));

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=114876&siteId=1