There's a String array that I have which has setter and getter methods. How do I directly pass values {"one", "two"}
to the setter method rather than setting the values to a variable first and then passing the parameter?
String[] arr1 = {};
public String[] getArr1() {
return arr1;
}
public void setArr1(String[] arr1) {
this.arr1 = arr1;
}
..expecting something like setArr1(?);
...
You could use setArr1(new String[]{"one", "two"})
Alternatively, you could make use of varargs and change your method signature to
setArr1(String... values)
and use the method as setArr1("one", "two")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With