Java | 基础归纳 | Map.Entry<String, String>

 1 public class Test {
 2     private static Map<String,String> student;
 3     
 4     private static void init() {
 5         student = new LinkedHashMap<String,String>();
 6         student.put("16010001", "tom");
 7         student.put("16010002", "tony");
 8         student.put("16010003", "j");
 9         student.put("16010004", "yy");
10     }
11     
12     public static void main(String[] args) {
13         init();
14          String key = null;
15          Scanner stdin = new Scanner(System.in);
16          System.out.println("Choose a SchoolId:");
17          for(Map.Entry<String, String> stu:student.entrySet()) {
18              System.out.println(stu.getKey()+"	" + stu.getValue());
19          }
20          while(key == null) {
21               key = stdin.nextLine();
22               if (student.get(key) == null) {
23                     System.out.println("Invalid choice!");
24                     key = null;
25                 }
26          }
27          
28          System.out.println("Success!");
29     }
30 }
原文地址:https://www.cnblogs.com/jj81/p/10040203.html