Java Interview Guide : 200+ Interview Questions and Answers - Collection Code Examples

Java Interview Guide : 200+ Interview Questions and Answers - Collection Code Examples

Assessment

Interactive Video

•

Information Technology (IT), Architecture, Physical Ed

•

University

•

Practice Problem

•

Hard

Created by

Wayground Content

FREE Resource

The video tutorial provides an in-depth exploration of Java collections, covering various implementations such as ArrayList, HashSet, TreeSet, HashMap, and TreeMap. It explains operations like adding, removing, and sorting elements, and highlights the use of Comparable and Comparator interfaces for sorting. The tutorial also delves into the functionality of NavigableSet and NavigableMap, as well as the PriorityQueue with natural and custom ordering. Finally, it discusses static methods in the Collections class, offering practical examples and coding exercises to reinforce learning.

Read more

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What happens when you add an element to an ArrayList without specifying an index?

The element is not added.

The element is added at the beginning of the list.

The element is added at the end of the list.

The element replaces the first element.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which method would you use to check if an ArrayList contains a specific element?

indexOf

contains

get

add

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What must a class implement to be sorted using Collections.sort()?

Serializable

Comparator

Iterable

Comparable

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How can you sort a collection in descending order?

Use Collections.reverseOrder()

Use a custom Comparator

Use Collections.sort() with a flag

Use a custom Comparable

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is a key characteristic of a HashSet?

It maintains elements in insertion order.

It does not allow duplicate elements.

It sorts elements in natural order.

It allows duplicate elements.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In a TreeSet, how are elements stored?

In insertion order

In reverse order

In random order

In sorted order

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What happens when you add a duplicate key to a HashMap?

The new value replaces the old value.

The key is ignored.

An error is thrown.

Both values are stored.

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?