Do Numbers inside such brackets { } always belong to arrays or can it be a primitive Type too?
The exact task is: Decide for the following values (!) whether Java provides primitive data types for their representation. If yes, specify all matching ones.
I'm only not sure about this one: {1,4,2} There isn't any int [ ] infront of that, that's why i'm asking.
(sorry for the dumb question, very big noob here)
CodePudding user response:
The code :
int[] array = {1,2,3};
Is equivalent to :
int[] array = new int[3];
array[0] = 1;
array[1] = 2;
array[2] = 3;
In java, arrays are objects (even if it's an array of primitive type)