Creating an Array of Primitives Flashcards

1
Q

Give all the ways an array can be initialized !

A

int[] array1 = new int[] {1,2,3,4};
int[] array2 = {19,21,37,40};
int[] array3 = new int[3];
System.out.println(Arrays.toString(array1)); // [1, 2, 3, 4]
System.out.println(Arrays.toString(array2)); // [19, 21, 37, 40]
System.out.println(Arrays.toString(array3)); // [0, 0, 0]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Give a characteristic of arrays !

A

Arrays can contain duplicates as well as ArrayList

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Define an anonymous array !

A

printArray(new int[]{1, 2, 3, 4, 5}); // Anonymous array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Give all the places where you can place the brackets in an array declaration !

A

int[] array1 = new int[] {1,2,3,4};
int array2[] = {19,21,37,40};
System.out.println(Arrays.toString(array1)); // [1, 2, 3, 4]
System.out.println(Arrays.toString(array2)); // [19, 21, 37, 40]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly