Queue interface in java

queue interface in java extends the collection interface and it is available in java.util package. Java queue maintains the orders of the elements in FIFO(First In First Out) manner. In FIFO, the first element removes first, and the last element removes at last. Java queue is a collection that is used to hold the elements … Read more

Similarities between HashSet, LinkedHashSet, TreeSet

In this post we will see what are the similarities between Similarities between HashSet, LinkedHashSet, TreeSet. We are assuming, you have read the HashSet, LinkedHashSet and TreeSet. There are some more post related to these class, that is also important for interview questions.1. Difference between HashSet and TreeSet2. HashSet vs LinkedHashSet Similarities between HashSet, LinkedHashSet, … Read more

Difference between HashSet and TreeSet

HashSet and TreeSet, both are used to store unique elements. Because both do not allow duplicate elements. There are a lot of similarities because both implements Set interface. But there is some unique difference between them. In this post, we will discuss the difference between HashSet and TreeSet. If you are not familiar with internal … Read more

comparator() method in java

In this post, we will learn about the comparator() method of TreeSet class. If you haven’t read about Comparator in java then you must it the Java Comparator first. Here is the java comparator tutorial in which we have discussed the working of the Comparator interface with different types of examples. Comparator comparator(): It returns … Read more

contains() method in java

The contains() method in java is declared in Collection interface. But if you are finding about java string contains method then you can click here. The contains method in java is used to check the given element is exist in collection or not. We will discuss it in detail. As we know collection interface is … Read more

Java TreeSet

In java, Set interface is one of the most important interfaces implemented by HashSet, LinkedHashSet, and TreeSet. If you haven’t read HashSet and LinkedHashSet yet, then you should read them first. In this post, we will read what is TreeSet in java and Java TreeSet example. You can read it with an example from here.1. … Read more

spliterator() method

spliterator() method: The spliterator in Java method of LinkedHashSet class utilizes to creates a late-binding and fail-fast Spliterator. It returns a Spliterator of the same elements as the LinkedHashSet. It returns the object of the Spliterator. Output:JAVAGOALRAVI

clear() method

clear() method: This Clear function in Java method is used to remove all the elements from the LinkedHashSet. Its return type is void. It means this method doesn’t returns anything. Output: Name from list = JAVAName from list = SITEName from list = GOALName from list = RAVIAfter Clear() method list is empty : true

LinkedHashSet in java

We have read about the Set interface and the most common implementation of Set are HashSet, LinkedHashSet, and TreeSet. In this post, we will read LinkedHashSet in java and LinkedHashSet example in java. NOTE: HashSet doesn’t maintain the order of elements. It is an unorder implementation of the Set interface.LinkedHashSet maintains the insertion order of … Read more

How to add element in HashSet?

In this post, we will read how to add an element in HashSet. We have an add(E e) method that is used to add the element in HashSet. We already know, A HashSet can contain only unique elements. So let’s see how we can work with java hashset add() method. add(E e) method This add(E … Read more