Java

Let’s learn difference between hashset and treeset in java. Difference between hashset and treeset in java HashSet TreeSet hashset do not maintain any order. sorted according to natural order. If not use compareTo() method. uses equals() method for comparison. uses compareTo() method for ordering two objects. hashset is implemented using HashTable. TreeSet is implemented using…

Read More Difference between hashset and treeset in java

Let’s learn how to sort treeset in descending order in java. How to sort treeset in descending order in java In this post lets sort treeset elements in descending order or decreasing order. For this we are using descendingSet() method. This method returns a reverse order view of the elements contained in this set. import…

Read More How to sort treeset in descending order in java

Let’s learn java treemap comparator() method example. Java treemap comparator() method example TreeMap comparator() method returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys. Let’s see example on TreeMap comparator() method for natural ordering. import java.util.Comparator; import java.util.NavigableMap; import java.util.TreeMap; public…

Read More Java treemap comparator() method example

Let’s learn how to sort an array without using sort method in java. How to sort an array without using sort method in java In the below program on how to sort an array without using sort method we are not using Arrays.sort() method to sort given array. Meanwhile we are sorting array elements in…

Read More How to sort an array without using sort method in java

Let’s learn java switch case with multiple values. Java switch case with multiple values Let’s learn to check java switch case on multiple values. Here’s an example on java switch case multiple values. public class SwitchCaseMultipleValues { public static void main(String[] args) { int number = 1; switch(number) { case 1: case 2: System.out.println(“number 1”);…

Read More Java switch case with multiple values