0

What do the three dots after "Object" mean in this parameter declaration:

public static int queryCount (
    Connection conn, String whereClause,
    Object ... params)
    throws Exception

In what way does it differ from the parameter declaration Object params ?

Jonas Czech
  • 12,018
  • 6
  • 44
  • 65
user2867435
  • 3
  • 1
  • 2

3 Answers3

1

Three dots mean that there method can get as parameters as much argument of type Object as it likes. Reading more about "varargs" arguments could be helpful.

k4sia
  • 414
  • 1
  • 6
  • 18
0

In short, it's a syntactic sugar for array with restriction that this should be the last parameter in arguments list.

e.g. it's totally legal to declare main method as follows

public static void main(String... args) {}

And another feature of this, this argument is optional, but you still will get an empty array as a value of argument.

Admit
  • 4,897
  • 4
  • 18
  • 26
0

This feature was introduced in Java to hide the process of using Arrays as parameters, in form of varargs.
As the documentation states, the process is stil same but complexity has been reduced.

Please note following points:

  • This allows for entering an array or sequence of type specified.
  • This form must be used at last in parameters list.
  • This is not available in older version, so be careful if you plan to deploy to older versions of Java
Vikas Raturi
  • 916
  • 2
  • 13
  • 23