首页 > 代码库 > 集合框架练习12

集合框架练习12

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Map.Entry;
import java.util.Set;


public class TeachClass {
    public static void main(String[] args) {
        String[]pro={"tom,corejava","john,oracle","susan,oracle","jerry,jdbc","jim,unix","kevin,jsp","lucy,jsp"};
        Map<String,String>map=new HashMap<String,String>();
        
        
        
        for(String s:pro){
            String[]v=s.split(",");
            map.put(v[0],v[1]);
        }
        map.put("allen", "jdbc");
        map.put("lucy", "corejava");
    Set<Map.Entry<String, String>>set=map.entrySet();    
    for(Entry<String, String> i:set){
    System.out.println(i);
    }
Scanner s=new Scanner(System.in);
System.out.println("请输入课程");
    String c=s.next();
    Set<String>sset=map.keySet();
    for(String i:sset){
        if(map.containsValue(c)){
            if(map.get(i).equals(c)){
                System.out.println(i);
            }
        }else{
            System.out.println("没有这门课");
        }
    }

    
}
}

 

集合框架练习12