2021SC@SDUSC
public class Pair extends Entry<String, String> {}
这里提到了Map.Entry<String, String>
用法如下
public class Test {
private static Map<String,String> student;private static void init() {
student = new LinkedHashMap<String,String>();
student.put("16010001", "tom");
student.put("16010002", "tony");
student.put("16010003", "j");
student.put("16010004", "yy");
}public static void main(String[] args) {
init();
String key = null;
Scanner stdin = new Scanner(System.in);
System.out.println("Choose a SchoolId:");
for(Map.Entry<String, String> stu:student.entrySet()) {
System.out.println(stu.getKey()+"\t" + stu.getValue());
}
while(key == null) {
key = stdin.nextLine();
if (student.get(key) == null) {
System.out.println("Invalid choice!");
key = null;
}
}System.out.println("Success!");
}
}
定义了一个Map<String, Class<?>> CLASS_MAP
初始化为CLASS_MAP = new HashMap<String, Class<?>>()
在CLASS_MAP里放入了如下类名和类