import java.util.Set;
import java.util.TreeMap;
class Demo
{
public static void main(String[] args)
{
//创建一个TreeMap集合
Map<String,String> ks = new TreeMap<>();
//填充
ks.put("04","小猫");
ks.put("02","大猫");
ks.put("01","黑猫");
ks.put("03","白猫");
//获取所以的键封装为一个Set给返回.
Set<String> key = ks.keySet();
for(String s : key){
//根据键获取每一个值.
System.out.println(s +","+ks.get(s));
}
}
}
|
|