Java Program to Get key from HashMap using the value

preview_player
Показать описание
#BackCoding

The HashMap class has many useful methods. For example, to add items to it, use the put() method:

#programming
#Java
#shorts
Рекомендации по теме
Комментарии
Автор

import java.io.*;
import java.util.*;
class ContactsInPhoneNo{

public static void main(String as[])throws IOException{

HashMap<String, Long> hm=new HashMap<>();

String name, str;
Long phno;

BufferedReader br=new BufferedReader(new

while(true){

System.out.println("1 ..Enter Phone number");
Data");
Data");
System.out.println("4.. Exit");

System.out.print("Enter your choice :");
int

switch(choice){

case 1:

System.out.print("Enter Name :");
name=br.readLine();

System.out.print("Enter Phone number");
str=br.readLine();

// phno=new Long(str);
phno=Long.valueOf(str);

hm.put(name, phno);
break;

case 2:

System.out.print("Enter Name");
name=br.readLine();
name=name.trim();

phno=hm.get(name);

System.out.println("Phone number:"+phno);

break;

case 3:

Set<String> set=new HashSet<String>();
set=hm.keySet();

System.out.println(set);
break;

case 4:
System.exit(0);

// default:
// System.out.println("incorrect Choice \n please try again");
}

}
}
}

BackCoding
Автор

2 questions:
What IDE are you using?
What does a BufferedInput do? I am learning Java myself.

jaxsyntax