Skip to main content

Posts

Showing posts with the label HashMap

HashMap in java | HashMap method in java with example | collections framework in java

 HashMap in java About Us : Introducing the RealNameHidden: Your Ultimate Guide to Java, Spring Boot, Hibernate, Databases, Problem Solving, and Interview Questions! Are you passionate about Java programming and eager to expand your knowledge in the world of software development? Look no further! Welcome to the realm of RealNameHidden, your go-to destination for all things related to Java, Spring Boot, Hibernate, Databases, Problem Solving, and Interview Questions. With a wealth of experience and expertise in the field, RealNameHidden is a dedicated YouTuber committed to sharing valuable insights, practical tips, and in-depth tutorials to help you master the intricacies of Java programming and its associated technologies. Whether you're a beginner taking your first steps into the programming world or an experienced developer seeking advanced concepts, this channel is designed to cater to all skill levels. RealNameHidden understands that Java programming is at the heart of modern so

how to iterate hashmap in java

how to iterate hashmap in java  for explanation watch video:: 1) import java.util.*; public class Test{   public static void main(String args[])  {   HashMap<Integer,String> hm = new HashMap<>(); hm.put(1,"raja"); hm.put(2,"ram"); hm.put(3,"mohan"); hm.put(4,"roy"); for(Map.Entry<Integer,String> e : hm.entrySet()){ System.out.println(e.getKey() + " "+e.getValue()); } }    }  2) Code: import java.util.*; public class Test{   public static void main(String args[])  {   HashMap<Integer,String> hm = new HashMap<>(); hm.put(1,"raja"); hm.put(2,"ram"); hm.put(3,"mohan"); hm.put(4,"roy"); //keys for(int i : hm.keySet()){ System.out.print(i+" "); } System.out.println(); for(String s : hm.values()){ System.out.print(s+" "); } System.out.println(); }    }  3) import java.util.*

Hash Tables: Ransom Note Hackerrank Solution - java | Hackerrank

 Hash Tables: Ransom Note Hackerrank Solution - java For Explanation Watch Video : Code : import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.function.*; import  java.util.regex.*; import  java.util.stream.*; import   static  java.util.stream.Collectors.joining; import   static  java.util.stream.Collectors.toList; class  Result {      /*      * Complete the 'checkMagazine' function below.      *      * The function accepts following parameters:      *  1. STRING_ARRAY magazine      *  2. STRING_ARRAY note      */      public   static   void  checkMagazine(List<String> magazine, List<String> note) {          //two times three is not four          //two times two is four         HashMap<String,Integer> hm =  new  HashMap<>();          for ( int  i= 0 ;i<magazine.size();i++){             String s = magazine.get(i);             hm.put(s,hm.getOrDefault

Program to find the frequency of characters in given string in java

Program to find the frequency of characters in given string in java  For Explanation Watch Video : Code:: import java.util.*; import java.io.*; import java.lang.*; class Test{ public static void main(String[] args) { String name = "idiot"; Map<Character,Integer> map = new HashMap<Character,Integer>(); for(int i=0;i<name.length();i++){ Character ch = name.charAt(i); map.put(ch,map.getOrDefault(ch,0)+1); } System.out.println(map); for(Map.Entry<Character,Integer> e : map.entrySet()){ System.out.println(e.getKey()+" "+e.getValue()); } } } o/p: {d=1, t=1, i=2, o=1} d 1 t 1 i 2 o 1