Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java int... array notation

Tags:

java

arrays

I've seen this before in a method parameter, and it appears to allow an arbitrary number of parameters to be stuffed in an array created at run-time. What's the official name of this language feature? Thanks!

    public static void trace(View view, RecyclerTraceType type, int... parameters) {

    RecyclerTrace trace = new RecyclerTrace();
    trace.position = parameters[0];
    trace.indexOnScreen = parameters[1];
}
like image 987
jtgameover Avatar asked Feb 24 '09 07:02

jtgameover


People also ask

What is difference between a [] and [] A?

What is the difference between int[] a and int a[] in Java? There is no difference in these two types of array declaration. There is no such difference in between these two types of array declaration. It's just what you prefer to use, both are integer type arrays.

How do you write an int array in Java?

arrayName = new int[size]; You have to mention the size of array during initialization. This will create an int array in memory, with all elements initialized to their corresponding static default value. The default value for an int is 0 .

What is an int [] in Java?

The Java int keyword is a primitive data type. It is used to declare variables. It can also be used with methods to return integer type values. It can hold a 32-bit signed two's complement integer.

How do you write an integer array?

var rank = new Array(1, 2, 3, 4); The Array parameter is a list of strings or integers. When you specify a single numeric parameter with the Array constructor, you specify the initial length of the array. The maximum length allowed for an array is 4,294,967,295.


1 Answers

You are seeing the Java 1.5 varargs feature. Under the hoods its just an array with syntactic sugaring.

like image 63
amit Avatar answered Nov 15 '22 19:11

amit