选择某种Map集合保存学号从1到15的学员的学号(键)和姓名(值)
package aaa;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap.KeySetView;
import javax.security.auth.kerberos.KerberosKey;
public class Map {
public static void main(String[] args) {
// TODO Auto-generated method stub
TreeMap tm = new TreeMap(new reset());
tm.put("01","shang");
tm.put("03","S_sadness");
tm.put("02","zhang");
tm.put("04","zhao");
tm.put("06","Tom");
tm.put("08","jesson");
tm.put("09","july");
tm.put("10","anhao");
tm.put("05","jim");
tm.put("07","jack");
Set KeySet= tm.keySet();
Iterator it = KeySet.iterator();
while(it.hasNext())
{
Object key = it.next();
Object value = tm.get(key);
System.out.println(key+":"+value);
}
}
import java.util.*;
import java.util.concurrent.ConcurrentHashMap.KeySetView;
import javax.security.auth.kerberos.KerberosKey;
public class Map {
public static void main(String[] args) {
// TODO Auto-generated method stub
TreeMap tm = new TreeMap(new reset());
tm.put("01","shang");
tm.put("03","S_sadness");
tm.put("02","zhang");
tm.put("04","zhao");
tm.put("06","Tom");
tm.put("08","jesson");
tm.put("09","july");
tm.put("10","anhao");
tm.put("05","jim");
tm.put("07","jack");
Set KeySet= tm.keySet();
Iterator it = KeySet.iterator();
while(it.hasNext())
{
Object key = it.next();
Object value = tm.get(key);
System.out.println(key+":"+value);
}
}
}
package aaa;
import java.util.Comparator;
public class reset implements Comparator {
public int compare(Object obj1,Object obj2){
String id1 = (String) obj1;
String id2 = (String) obj2;
return id1.compareTo(id2);
}
}