Arrays Flashcards

1
Q

What are the 3 ways to instantiate an array?

A
int[] arr1 = new int[3];
int[] arr2 = { 1, 2, 3 };
int[] arr3 = new int[] { 1, 2, 3 };
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the 2 ways to instantiate multidimensional arrays?

A
int[][] matrix = new [1][2];
int[][] matrix2 = {{1,2}};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What class could you use to create a stream out of an array?

A
int[][] matrix = {{1,2,3}};
Arrays.stream(matrix)...
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. What data structure is used to implement varargs?
  2. Code an example using varargs
A
  1. arrays
  2.  void sum(int... args) {
        Arrays.stream(args).sum();
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can an array be converted to a List?

A
Integer[] arr = { 1, 2, 3 };
List<Integer> list = Arrays.asList(arr);
 List<Integer> list2 = List.of(arr);
System.out.println(list); // [1, 2, 3]
System.out.println(list2); // [1, 2, 3]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What will the code bellow print?

int[] nums = {1,2,3};
int[] nums2 = {1,2,3};

System.out.println(nums == nums2);
System.out.println(Arrays.equals(nums, nums2));
A
  1. False
  2. True
How well did you know this?
1
Not at all
2
3
4
5
Perfectly