We didn't have feature that passing unspecified number of arguments to method, but this feature has been introduced with JDK 5.0.
Java considers the variable-length argument list as an array. This is represented by argument type followed by three dots in the declaration of the Method. The following example can explain about this
The method int sum(int…numbers) can take any number of parameters of type integer.
Java considers the variable-length argument list as an array. This is represented by argument type followed by three dots in the declaration of the Method. The following example can explain about this
The method int sum(int…numbers) can take any number of parameters of type integer.
public int sum(int...numbers) { |
Comments
Post a Comment