Skip to main content

Posts

Showing posts from February, 2020

TreeSet in Java

TreeSet in Java In this article, we are going to learn about what is TreeSet in Java. Also, we look at the upper hierarchy of TreeSet in Java. We will look at the methods provided by TreeSet.
Content of the ArticleWhat is TreeSet in Java?Hierarchy of the TreeSet in java?How to create an object of TreeSet in java?How to add elements to the TreeSet in java?How to iterate TreeSet in java?How to check whether an element is stored in the TreeSet in Java?How to remove elements from the TreeSet in java?Reverse order set provided by the TreeSet in Java?How to get sub-set from the TreeSet in Java?How to get first and last element from the TreeSet in Java?Few more methods of TreeSet in java
What is TreeSet in Java? TreeSet in java is an implementation of Set interface i.e., duplicate elements are not allowed, Set interface provides the facility to store and retrieve elements. TreeSet internally maintains a TreeMap as its internal data structure, so that all the operation made on the TreeSet tr…

How to sort HashMap by key and value in Java

How to Sort HashMap by key and value in Java In this article, we are going to have look at how to sort HashMap by key and how to sort HashMap by value in Java. We are going to learn different approaches to sort HashMap.

HashMap does not sort its key-value pair and also it does not maintain any order (neither insertion nor sorted). If we want to sort HashMap then we need to provide custom logic that can sort HashMap and To sort HashMap by key we can use either TreeMap or LinkedHashMap but in case of sort HashMap by value, we have the only option of LinkedHashMap as TreeMap cannot be used to sort HashMap by value.
Content of the articleHow to sort HashMap by key using TreeMap?How to sort HashMap by key using LinkedHashMap?How to sort HashMap by value using LinkedHashMap?How to sort HashMap by value in descending order
How to sort HashMap by key using TreeMap in Java To sort HashMap by key, we can use TreeMap class. TreeMap in java is used store key-value pairs and sort all the pairs w.…

TreeMap in Java

TreeMap in Java In this article, we are going to learn about TreeMap in Java what it is, various ways to create an instance of TreeMap, methods provided by TreeMap in Java and many more topics related to TreeMap in Java. Content of this articleWhat is TreeMap in Java?Hierarchy of the TreeMap in java?How to create an object of TreeMap in java?How to add key-value pairs into the TreeMap in java?How to get the data from the TreeMap in java?Collection Views Provided by TreeMap in JavaHow to check whether a key or a value is present or not within the TreeMap in Java?Reverse order view provided by the TreeMap in Java?How to get subMap from the TreeMap in Java?How to get first and last entry from the TreeMap in Java?Few more methods of TreeMap in Java
What is TreeMap in Java? TreeMap in java is an implementation of Map interface, which provides the facility to store and retrieve key-value pairs.
TreeMap internally implements the Red-Black Tree data structure and stores key-value pairs in the …

HashSet in Java

HashSet in Java In this article, we are going to learn about what is HashSet in Java. We also look at the methods provided by the HashSet in Java, how HashSet internally managed by Java and all.
Table of Content1. What is HashSet in Java?2. Hierarchy of the HashSet in java?3. How to create object of HashSet in java?4. How to add elements to the HashSet in java?5. How to iterate HashSet in java?6. How to check whether an elements is stored in the HashSet in Java?7. How to remove elements from the HashSet in java?8. Few more methods of HashSet in java9. How to create Array from HashSet in Java?10. How to sort HashSet in Java?
What is HashSet in Java? HashSet in java, is an implementation of Set interface of Java i.e., duplicate elements are not allowed. A Set is similar to a List but duplicate elements are allowed in a List.
HashSet is the part of Java Collection Framework. It is defined in java.util package and implements Set interface which provides standard method declaration to perfo…

Sort ArrayList in Java

How to sort ArrayList in Java In this article, we are going to learn how we can sort ArrayList in Java. ArrayList is one of the most important classes of Java and it is a part of the Java Collection Framework. To sort Arraylist in Java, first we should understand what is ArrayList in Java.
There is a number of ways to sort ArrayList in Java and it is very hard to incorporate all of those methods in a single post. So, we are going to learn the most common approaches to sort ArrayList in Java.
To have a basic idea of how we can sort ArrayList in Java, let's look at the very simple example to sort ArrayList in Java. ArrayList Sort Example 1 : Create a list of strings and sort in ascending orderArrayList<String> books = new ArrayList<>(); books.add("Programming in Java"); books.add("Let's Start JavaScript"); books.add("Data Structures"); books.add("Introduction to Algorithms"); books.add("Concept of Databases"); Collec…