What is an Iterator

Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk through a collection of objects, operating on each object in turn. Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable … Read more

What is Java Collections API

Java Collections framework API is a unified architecture for representing and manipulating collections. The API contains Interfaces, Implementations & Algorithm to help java programmer in everyday programming. In nutshell, this API does 6 things at high level Reduces programming efforts. – Increases program speed and quality. Allows interoperability among unrelated APIs. Reduces effort to learn … Read more

What is TreeSet

TreeSet – It is the implementation of SortedSet interface.This implementation provides guaranteed log(n) time cost for the basic operations (add, remove and contains). The class is not synchronized. In Core Java, a TreeSet is a class that implements the Set interface and extends the AbstractSet class. It is part of the Java Collections Framework and is … Read more

How to Convert a string array to arraylist

new ArrayList(Arrays.asList(myArray)) To convert a String array to an ArrayList in Core Java, you can use the Arrays.asList() method to convert the array to a List and then create an ArrayList from that List. Here’s an example: java import java.util.ArrayList; import java.util.Arrays; import java.util.List;public class StringArrayToArrayList { public static void main(String[] args) { // Example String … Read more

What Method should the Key Class of Hashmap Override

The methods to override are equals() and hashCode(). For the HashMap class in Java, the key class should override the hashCode() and equals() methods. These methods are crucial for proper functioning of the HashMap as they determine how keys are stored and retrieved in the underlying data structure. Here’s a brief explanation of each method: … Read more