1.

In the given code below, what is the significance of ... ?

Answer»

public void fooBarMethod(String... variables){ // method CODE}

  • ABILITY to provide ... is a feature called varargs (variable arguments) which was introduced as part of Java 5.
  • The function having ... in the above example indicates that it can receive multiple arguments of the datatype String.
  • For example, the fooBarMethod can be called in multiple ways and we can still have one method to process the DATA as shown below:
fooBarMethod("foo", "bar");fooBarMethod("foo", "bar", "boo");fooBarMethod(new String[]{"foo", "var", "boo"});public void myMethod(String... variables){ for(String variable : variables){ // business LOGIC }}


Discussion

No Comment Found