Add values from basic array to Set<String>

  • A+

I have this:

  private Set<String> fields = new HashSet<>();    public void fields(String... s){     this.fields.addAll(s);   } 

but that doesn't compile, it says:

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?


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



:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: