ArrayLists

ArrayLists

11th - 12th Grade

10 Qs

quiz-placeholder

Similar activities

Find Maximum Algorithm Quiz

Find Maximum Algorithm Quiz

12th Grade

15 Qs

AP Comp (POP Quiz)

AP Comp (POP Quiz)

9th - 12th Grade

7 Qs

12cs cha9

12cs cha9

12th Grade

12 Qs

Computer Programming REVIEW

Computer Programming REVIEW

9th - 12th Grade

15 Qs

Lists quiz intermediate

Lists quiz intermediate

11th Grade

7 Qs

ArrayLists

ArrayLists

11th - 12th Grade

10 Qs

نادي البرمجة ضواحي القدس م4

نادي البرمجة ضواحي القدس م4

5th - 11th Grade

13 Qs

mod 3 quiz

mod 3 quiz

9th - 12th Grade

10 Qs

ArrayLists

ArrayLists

Assessment

Quiz

Computers

11th - 12th Grade

Medium

Used 16+ times

FREE Resource

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

What is printed as a result of executing the following code?

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

alist.add(1);

alist.add(2);

alist.remove(1);

alist.add(1, 3);

alist.set(1, 4);

alist.add(5);

System.out.println(alist);

[1, 4, 5]

[1, 4, 3, 5]

[2, 4, 5]

[2, 4, 3, 5]

2.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Which statement below is the correct way to retrieve the first element in the nums ArrayList?

nums.get(0)

nums[0]

nums(0)

nums[1]

3.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Given the ArrayList nums with the values [3, 7, 6, 0], what code below is the proper way to change the 7 to be a 5?

nums.set(1, 5)

nums.set(7, 5)

nums.set(5, 2)

nums[2] = 5

4.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

What is printed as a result of executing the following code segment?

List<Integer> list1 = new ArrayList<Integer>();

list1.add(new Integer(1));

list1.add(new Integer(2));

list1.add(new Integer(3));

list1.set(2, new Integer(4));

list1.add(2, new Integer(5));

list1.add(new Integer(6));

System.out.println(list1);

[1, 2, 3, 4, 5]

[1, 2, 4, 5, 6]

[1, 2, 5, 4 ,6]

[1, 5,2, 4 ,6]

5.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Given the following code and assume that nums initially contains [0, 0, 4, 2, 5, 0, 3], what will nums contain as a result of executing numQuest?

private List<Integer> nums;


// precondition: nums.size() > 0;

// nums contains Integer objects

public void numQuest()

{

int k = 0;

Integer zero = new Integer(0);

while (k < nums.size())

{

if (nums.get(k).equals(zero))

nums.remove(k);

else

k++;

}

}

[0, 4, 2, 5, 3]

[3, 5, 2, 4, 0, 0, 0]

[0, 0, 0, 4, 2, 5, 3]

[4, 2, 5, 3]

6.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Which of the following best describes the behavior of process1 and process2 (shown below)?

public static List<Integer> process1(int n)

{

List<Integer> someList = new ArrayList<Integer>();

for (int k = 0; k < n; k++)

someList.add(k);

return someList;

}


public static List<Integer> process2(int n)

{

List<Integer> someList = new ArrayList<Integer>();

for (int k = 0; k < n; k++)

someList.add(k, k);

return someList;

}

Both methods produce the same result, and process1 is faster than process2.

The two methods produce different results and take the same amount of time.

The two methods produce different results, and process1 is faster than process2.

The two methods produce different results, and process2 is faster than process1.

Both methods produce the same result and take the same amount of time.

7.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

What is printed as a result of executing the following code segment?

List<Integer> aList = new ArrayList<Integer>();

aList.add(new Integer(1));

aList.add(new Integer(2));

aList.add(1, new Integer(5));

aList.set(1, new Integer(4));

aList.add(new Integer(6));

aList.add(new Integer(3));

System.out.println(aList);

[1, 2, 5, 4, 6, 3]

[6, 5, 4, 3, 2, 1]

[1, 2, 3, 4, 5, 6]

[1, 4, 2, 6, 3]

. [1, 2, 4, 6, 3]

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?