import java.util.*;public class TreeMapDemo {
public static void main(String[] args) {
TreeMap<String,Double>tm = new TreeMap<String,Double>();
tm.put("John Doe",3434.34);
tm.put("Tom Smith",123.22);
tm.put("Jane", 1378.00);
tm.put("Tod Hall", 99.22);
tm.put("Ralph", -19.80);
Set<Map.Entry<String,Double>>set = tm.entrySet();
for(Map.Entry<String, Double>me:set){
System.out.println(me.getKey()+": " );
System.out.println(me.getValue()+": ");
}
System.out.println();
double balance = tm.get("John Doe");
tm.put("John Doe", balance + 1000);
System.out.println("John Doe's new balance: " + tm.get("John Doe"));
}
}
我是想在这段代码中实现NavigableSet<k>descendingKeySet();;;NavigableMap<k,v>descendingMap()方法,不知该如何使用,还有就是关于API文档中的方法,例如:Set<Map.Entry<k,v>>entrySet(),方法但是在代码中实现方式却是Set<Map.Entry<String,Double>>set = tm.entrySet();我知道Set<Map.Entry<k,v>>是返回类型也会使用这种方法了可是总不知道是为什么
还是所以有点迷惑,希望各位能够详细解释一下!谢了
public static void main(String[] args) {
TreeMap<String,Double>tm = new TreeMap<String,Double>();
tm.put("John Doe",3434.34);
tm.put("Tom Smith",123.22);
tm.put("Jane", 1378.00);
tm.put("Tod Hall", 99.22);
tm.put("Ralph", -19.80);
Set<Map.Entry<String,Double>>set = tm.entrySet();
for(Map.Entry<String, Double>me:set){
System.out.println(me.getKey()+": " );
System.out.println(me.getValue()+": ");
}
System.out.println();
double balance = tm.get("John Doe");
tm.put("John Doe", balance + 1000);
System.out.println("John Doe's new balance: " + tm.get("John Doe"));
}
}
我是想在这段代码中实现NavigableSet<k>descendingKeySet();;;NavigableMap<k,v>descendingMap()方法,不知该如何使用,还有就是关于API文档中的方法,例如:Set<Map.Entry<k,v>>entrySet(),方法但是在代码中实现方式却是Set<Map.Entry<String,Double>>set = tm.entrySet();我知道Set<Map.Entry<k,v>>是返回类型也会使用这种方法了可是总不知道是为什么
还是所以有点迷惑,希望各位能够详细解释一下!谢了
NavigableMap<k,v>descendingMap()这两个方法吗 ?
或者举一个实例实现这两个方法
这是在NavigableMap接口中定义的方法 可是我不知道使用!很郁闷!
和NavigableMap<k,v>descendingMap()这两个方法的实例吗?最好是在TreeMap类中!谢谢了!