-3

I am looking at methods of class Arrays:

  1. public static int hashCode(double a[])

  2. public static void parallelSort(int[] a, int fromIndex, int toIndex)

  3. public static <T> List<T> asList(T... a)

I see 3 different types of how array could be declared as input parameter. What is the differenece?

Subodh Joshi
  • 10,006
  • 23
  • 84
  • 177
Lesya Makhova
  • 1,190
  • 2
  • 13
  • 27
  • 2
    For the first two: http://stackoverflow.com/questions/1200621/declare-array-in-java The third one is a var-args array. – Jeroen Vannevel Aug 12 '15 at 19:26
  • 1
    As you are asking this question, I would really suggest you read through [The Java Tutorials](https://docs.oracle.com/javase/tutorial/java/TOC.html) from start to finish - this is a very basic question. Most basic questions will be answered in those tutorials – Andy Brown Aug 12 '15 at 19:33

1 Answers1

2

From The Java Tutorials:

An array's type is written as type[], where type is the data type of the contained elements; the brackets are special symbols indicating that this variable holds an array

and

You can also place the brackets after the array's name ... float anArrayOfFloats[]; However, convention discourages this form; the brackets identify the array type and should appear with the type designation.

And in the case of method parameters:

You can use a construct called varargs to pass an arbitrary number of values to a method ... To use varargs, you follow the type of the last parameter by an ellipsis (three dots, ...), then a space, and the parameter name. The method can then be called with any number of that parameter, including none.

Andy Brown
  • 18,200
  • 3
  • 46
  • 59