Skip to content

Instantly share code, notes, and snippets.

@roshanadh
Last active April 10, 2019 06:58
Show Gist options
  • Save roshanadh/b51335eb969ed900a8718e99de8a91e3 to your computer and use it in GitHub Desktop.
Save roshanadh/b51335eb969ed900a8718e99de8a91e3 to your computer and use it in GitHub Desktop.
HashMap implementation in Java
import java.util.HashMap;
import java.util.Scanner;
public class HashMapLogin
{
public static void main(String[] args)
{
//Instantiating HashMap class with <Key,Value> pair both represented in String
HashMap<String,String> creds=new HashMap();
//Defining two Scanner objects for user input
Scanner scanID=new Scanner(System.in);
Scanner scanPass=new Scanner(System.in);
for(int i=0;i<=5;i++)
{
System.out.println("Enter ID: ");
String id=scanID.next();
System.out.println("Enter Password for "+id);
String pass=scanPass.next();
creds.put(id,pass);
}
System.out.println("Enter ID to query the Password: ");
Scanner scanIDQuery=new Scanner(System.in);
String idQuery=scanIDQuery.next();
System.out.println("The password for ID: "+idQuery+" is: "+creds.get(idQuery));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment