We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Java
  3. Data Structures
  4. Java Map
  5. Discussions

Java Map

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 318 Discussions, By:

recency

Please Login in order to post a comment

  • aymenrjaibi2301
    57 minutes ago+ 0 comments

    **Solution Java : **

    class Solution{
    	public static void main(String []argh)
    	{
    		Scanner in = new Scanner(System.in);
    		int n=in.nextInt();
    		in.nextLine();
            Map<String, Integer> mp = new HashMap<String,Integer>();
            
    		for(int i=0;i<n;i++)
    		{
    			String name=in.nextLine(); 
    			int phone =in.nextInt();
                in.nextLine();
                mp.put(name,phone);
    		}
            
            
    		while(in.hasNext())
    		{
    			String s = in.nextLine();
            
                if(mp.containsKey(s)){
                    String value =mp.get(s).toString();
                    System.out.println(s+ "=" +value);
                    
                }else{
                    
                    System.out.println("Not found");
                }
    		}
    	}
    }
    
    0|
    Permalink
  • jasleenkaur55661
    1 day ago+ 0 comments

    class Solution{ public static void main(String []argh) { Scanner in = new Scanner(System.in); Map phoneMap = new HashMap<>(); int n=in.nextInt(); in.nextLine(); for(int i=0;i

    0|
    Permalink
  • fmathais
    7 days ago+ 0 comments

    Super simple and self explainatory solution:

    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String args[]) {
            Scanner in = new Scanner(System.in);
            int rows = in.nextInt();
            in.nextLine();
            Map<String, String> contacts = new HashMap<>();
            
            for(int i = 0; i < rows; i++) {
                String name = in.nextLine();
                String number = in.nextLine();
                contacts.put(name, number);
            }
            
            while(in.hasNext()) {
                String name = in.nextLine();
                
                if (contacts.get(name) == null) {
                    System.out.println("Not found");
                } else {
                    System.out.println(String.format("%s=%s", name, contacts.get(name)));
                }
            }
        }
    }
    
    0|
    Permalink
  • burhanahmedov76
    2 weeks ago+ 0 comments

    //Complete this code or write your own from scratch import java.util.; import java.io.;

    class Solution{ public static void main(String []argh) { Scanner in = new Scanner(System.in); int n=in.nextInt(); in.nextLine(); HashMap map = new HashMap<>();

        for(int i=0;i<n;i++)
        {
            String name=in.nextLine();
            int phone=in.nextInt();
            in.nextLine();
            map.put(name, phone);
        }
        while(in.hasNext())
        {
            String s=in.nextLine();
            if(map.get(s)!=null){
            System.out.println(s+"="+map.get(s));
            }else{
                System.out.println("Not found");
            }
    
        }
    
    }
    

    }

    0|
    Permalink
  • Turqay_T
    2 weeks ago+ 1 comment

    import java.util.HashMap; import java.util.Scanner;

    public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); scanner.nextLine();

        HashMap<String, String> phoneBook = new HashMap<>();
    
        // Read n phone book entries
        for (int i = 0; i < n; i++) {
            String name = scanner.nextLine();
            String phoneNumber = scanner.nextLine();
            phoneBook.put(name, phoneNumber);
        }
    
        // Look up phone numbers for m queries
        while (scanner.hasNext()) {
            String name = scanner.nextLine();
            String phoneNumber = phoneBook.get(name);
            if (phoneNumber != null) {
                System.out.println(name + "=" + phoneNumber);
            } else {
                System.out.println("Not found");
            }
        }
    
        scanner.close();
    }
    

    }

    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy