Search Header Logo

JAVA-QUEUE

Authored by RAVINDER B

Computers

University

Used 2+ times

JAVA-QUEUE
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

PriorityQueue<Integer> pq = new PriorityQueue<>();

pq.add(50);

pq.add(10);

pq.add(40);

System.out.println(pq);

[50, 10, 40]

[10, 40, 50]

Random order

error

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Queue<Integer> q = new ArrayDeque<>();

q.add(1);

q.add(2);

q.add(3);

q.remove();

q.remove();

q.add(4);

System.out.println(q.peek());

1

2

3

4

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is true about Java Queue?

add() throws exception if queue is full, offer() returns false.

remove() returns null if queue is empty.

poll() throws exception if queue is empty.

peek() throws exception if queue is empty.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Deque<Integer> dq = new ArrayDeque<>();

dq.addFirst(10);

dq.addLast(20);

dq.addLast(30);

dq.removeFirst();

dq.addFirst(40);

System.out.println(dq);

[10, 20, 30]

[20, 30, 40]

[40, 20, 30]

[40, 10, 20]

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Queue<Integer> q = new LinkedList<>();

System.out.println(q.poll());

System.out.println(q.remove());

null, null

null, Exception

Exception, null

Exception, Exception

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

PriorityQueue<String> pq = new PriorityQueue<>();

pq.add("banana");

pq.add("apple");

pq.add("cherry");

System.out.println(pq.poll());

System.out.println(pq.peek());

banana, apple

apple, banana

apple, cherry

banana, cherry

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Queue<Integer> q = new LinkedList<>();

q.add(null);

System.out.println(q.peek());

null

Compilation error

Runtime exception

undefined behavior

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?