Java Program to Get key from Hashtable using the value

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

Hashtable is similar to HashMap which can store elements in the form of key-value pairs. But Hashtable is synchronized assuring proper results even if multiple threads act on it simultaneously We can write Hashtable class as:

we did not mention any capacity for the Hashtable. The default initial capacity of this Hashtable

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

import java.io.*;
import java.util.*;

class HashTableDemo{

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

Hashtable<String, Integer> ht=new Hashtable<>();

BufferedReader br=new BufferedReader(new

int choice;
String ch;
String search;

do{

Menu

System.out.println("1..Add an Element :");
System.out.println("2..Search Element");
System.out.println("3.. Display");
System.out.println("4.. Exit");

System.out.print("Enter your Choice :");


switch(choice){

case 1:
System.out.print("Enter player name: ");
String name=br.readLine();

System.out.print("Enter Scors :");
int

ht.put(name, sc);
break;

case 2:
System.out.print("Enter player name :");

String name1=br.readLine();

Integer score=ht.get(name1);
if(score!=null){

int scr=score.intValue();
System.out.println(name1+" Scores :"+scr);

}else{
System.out.println("Player not found");
}
break;

case 3:
System.out.println("The Player names");
Enumeration e=ht.keys();
while(e.hasMoreElements()){


}
break;

case 4:
System.exit(0);

default:
System.out.println("Incorrect Choice please try again");


}
System.out.println("Do u want continue program(yes/no)");
ch=br.readLine();


}
}
}

BackCoding