Java Collections Programming Interview Questions Answers - 2

Question: 6

What is an iterator?

  • Iterator interfaces provides methods to iterate over any Collection.
  • We can get iterator instance from a Collection using iterator() method.
  • Iterator takes the place of Enumeration in the Java Collections Framework.
  • Iterators allow the caller to remove elements from the underlying collections during the iteration.
  • Java Collection iterator provides a generic way for traversal through the elements of a collection and implements Iterator Design Pattern.

Question: 7

What are collection related features in java 8?

Java 8 has brought major changes in the Collection API. Some of the changes are

Java Stream API for collection classes for supporting sequential as well as parallel processing.

Iterable interface is extended with forEach() default method that we can use to iterate over a collection.

It is very helpful when used with lambda expressions because its argument.

Question: 8

How do you remove element during iteration?

Iterator also has a method remove() when remove is called, the current element in the iteration is deleted.

Question: 9

Why we override equals() method?

The equals() method is used to check whether two objects are same or not.

It needs to be overridden if we want to check the objects based on property.

Question: 10

How will you load a specific locale?

By ResourceBundle.getBundle() method.

Related Questions