Saved Bookmarks
| 1. |
What do you understand by the ... in the below method parameters? |
|
Answer» public void someMethod(String... info){ // method body } The 3 dots feature was started in Java 5 and the feature is known as varargs (variable arguments). This simply means that the method can receive one or more/multiple String arguments as shown below:
These received arguments can be used as an array and can be accessed by iterating through loops as shown below: public void someMethod(String... info){for(String someInfo : info){ // any operation } // The info can be accessed using index based loops too for( int i = 0; i < info.length; i++){ String s = info[i]; //some operation } } |
|