ArrayLists

ArrayLists

11th - 12th Grade

10 Qs

quiz-placeholder

Similar activities

básico de Code

básico de Code

10th - 12th Grade

14 Qs

HTML

HTML

9th - 12th Grade

12 Qs

Intro-2

Intro-2

12th Grade

15 Qs

CSS background, border

CSS background, border

11th Grade

10 Qs

Keyboarding Terms

Keyboarding Terms

9th - 12th Grade

10 Qs

สอบเก็บคะแนน ไพทอน ม.4

สอบเก็บคะแนน ไพทอน ม.4

9th - 12th Grade

10 Qs

Word basics

Word basics

8th - 12th Grade

10 Qs

ArrayLists

ArrayLists

Assessment

Quiz

Computers

11th - 12th Grade

Practice Problem

Medium

Used 16+ times

FREE Resource

AI

Enhance your content in a minute

Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...

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]

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?