JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

How to find the Entry with largest Key in a Java Map Collection

8:53 PM
  How to find the Entry with largest Key in a Java Map  Collection Given a map in Java, the task is to find out the entry in this map with the highest key. Examples: Input: Map = {ABC = 10, DEF = 30, XYZ = 20} Output: XYZ = 20 Input: Map = {1 = 40, 2 = 30, 3 = 60} Output: 3 = 60 Approach Iterate the map entry by entry for (Map.Entry entry : map.entrySet())  {     // Operations } Store the first entry in a reference variable to compare to initially. If the current entry’s key is greater than the reference entry’s value, then store the current entry as the reference entry. Repeat this process for all the entries in the map. In the end, the reference variable has the required entry with the highest key in the map. Print this entry Below is the implementation of the above approach: filter_none edit play_arrow brightness_4 // Java program to find entry  // with highest key in a map     import java.util.*;     public class GFG {         // Find the entry with highest key      public static &

how to get java collection Map size() Method in Java With Examples

8:35 PM
How to get java collection Map size() Method in Java With Examples Map size() method in Java is used to get the total number entries i.e, key-value pair. So this method is useful when you want total entries present on the map. If the map contains more than Integer.MAX_VALUE elements return Integer.MAX_VALUE. Parameters: (This method does not take any parameters.) Return value (This method returns the number of key-value mappings in this map.) Syntax: int size(); Example 1: For non-generic input // Java program to illustrate  // the Map size() Method  import java.util.*;     public class MapSizeExample {             // Main Method      public static void main(String[] args)      {          Map map = new HashMap();                     // Adding key-values          map.put(1, "delhi");          map.put(5, "mumbai");          map.put(2, "noida");          map.put(6, "meerut");                     // using the method          System.out.println("

core java collection Map program for interview

8:27 PM
  Core-Java Collection Map program for interview preparation : how to get java collection Map size() Method in Java With Examples How to find the Entry with the largest Key in a Java Map How to Clone a Map in Java ArrayList vs. HashMap in Java How to create a TreeMap in reverse order in Java How to check if a key exists in a HashMap in Java Difference between HashMap and HashSet Remove an Entry using value from HashMap while Iterating over it Remove an Entry using key from HashMap while Iterating over it Flatten a Stream of Map in Java using forEach loop Replace null values with default value in Java Map Program to Convert List to Map in Java Sort elements by frequency | Set 5 (using Java Map) Program to Convert HashMap to TreeMap in Java Traverse through a HashMap in Java Initialize HashMap in Java ImmutableMap, as suggested by the name, is a type of Map which is immutable. It means that the content of the map are fixed or… Read More Given marks scored out of 100 by a student in subje

.