wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Arrays, 2D Arrays, and ArrayLists

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

How do you declare an array?

a)

int[] arr = int[5];

b)

int[] arr = new Array[5];

c)

int[] arr = new int[5];

d)

int[] arr = new int[1, 2, 3, 4, 5];

2.

how do you create a 2D Array?

a)

int[][] matrix = new int[3][3];

b)

int[] matrix = new int[3][3];

c)

int[][] matrix = int[3][3];

d)

int[] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

3.

how do you create an ArrayList?

a)

ArrayList<Integer> myList;

myList = new ArrayList<int>();

b)

ArrayList<Integer> myList = new ArrayList<Integer>;

c)

ArrayList<int> myList = new ArrayList<int>();

d)

ArrayList<Integer> myList = new ArrayList<Integer>();

4.

how do you import utilities in order to create and use ArrayLists?

a)

import.java.util*;

b)

import java.util*;

c)

import java.util;

d)

import java.util.*;

5.

what is the difference between an array and an ArrayList?

a)

Arrays are objects but ArrayLists are not objects.

b)

ArrayLists are objects but Arrays are not objects.

c)

The size of an ArrayList can change, but the size of an Array can not.

d)

The size of an Array can change, but the size of an ArrayList can not.

6.

how do you find the length of an ArrayList?

a)

myList.length();

b)

myList.lenght;

c)

myList.size();

d)

myList.size;

7.

how do you find the element in row 2, column 3 of a 2D array?

a)

int x = arr[2][3];

b)

int x = arr[3][2];

c)

int x = [2][3];

d)

arr[3][2];

8.

what does this code output for the following 2D array?

{ {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }

a)

1 2 3

4 5 6

7 8 9

b)

1 2 3 4 5 6 7 8 9

c)

1, 2, 3, 4, 5, 6, 7, 8, 9

d)

1, 2, 3,

4, 5, 6,

7, 8, 9

9.

how do you find the length of an Array?

a)

arr.length();

b)

arr.length;

c)

arr.size();

d)

arr.size;

10.

how do you find the number of columns in a 2D array?

a)

int numOfColumns = matrix.length;

b)

int numOfColumns = matrix.length();

c)

int numOfColumns = matrix[0].length();

d)

int numOfColumns = matrix[0].length;

11.

What code is used to find the value of the last element in an ArrayList?

a)

myList.size()-1;

b)

myList.length()-1;

c)

myList.size();

d)

myList.length;

12.

Which is correct code to access an element of an ArrayList in Java?

a)

myList.get(index);

b)

myList[index];

c)

myList(index);

d)

myList.index;

13.

what code is used to find the value of the last element of an Array?

a)

arr.length;

b)

arr.length()-1

c)

arr.length - 1;

d)

arr.length();

14.

What number do you start on when you assign indexes elements in an Array

a)

0

b)

1

15.

For the following Array, what does the code return? :

int[] arr = {3, 5, 8, 19, 32};

int num = arr[3];

System.out.println(num);

a)

3

b)

8

c)

19

d)

5