import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
public class HashMapEx {
public static void main(String[] args) {
HashMap<String, String> h = new HashMap<String, String>(); //ํ ์์ ๋ฐ์
Scanner sc = new Scanner(System.in);
h.put("Python","ํ์ด์ฌ");
h.put("Java", "์๋ฐ");
h.put("Database", "๋ฐ์ดํฐ๋ฒ ์ด์ค");
Set<String> keys = h.keySet(); //์์ ์๋ String์ผ๋ก ํค๋ฅผ ์ง์
Iterator<String> it = keys.iterator();
while(it.hasNext()) { //๋ชจ๋ ์ ๋ณด ์์ฐจ ์ถ๋ ฅ
String key = it.next();
String val = h.get(key);
System.out.println(key+"===>"+val);
}
while(true) {
System.out.print("์๋ฌธ ๊ณผ๋ชฉ๋ช
: ");
String title = sc.next();
if(title.equals("exit")) {
System.out.println("bye~~");
break;
}
String val = h.get(title);
if(val == null)
System.out.println("์๋ ๊ณผ๋ชฉ์
๋๋ค.");
else
System.out.println(title+"===>"+val);
}
}
}
728x90
๋ฐ์ํ
0