[英]Can I use a Comparator class to order a TreeMap in Java 1.6?
I have the following problem into a Java 6 application I try to do 我在尝试执行的Java 6应用程序中遇到以下问题
QuotaTirComparator bvc = new QuotaTirComparator(mappaQuote);
TreeMap<Integer, QuotaTir> sorted_map = new TreeMap<Integer, QuotaTir>(bvc);
to obtained a sorted TreeMap. 获得排序的TreeMap。
But Eclipse give me the following error message: 但是Eclipse给我以下错误消息:
The constructor TreeMap<Integer,QuotaTir>(QuotaTirComparator) is undefined
Why? 为什么? Is this feature not enabled in Java 6?
Java 6中未启用此功能吗? What is wrong?
怎么了? What am I missing?
我想念什么?
My guess is that QuotaTirComparator
is not a Comparator
Obviously, the Comparator must be for the keys, not the values. 我的猜测是
QuotaTirComparator
不是Comparator
显然,Comparator必须用于键,而不是值。 As Integer
already has a natural ordering, I would try removing the comparator altogether. 由于
Integer
已经具有自然顺序,因此我将尝试完全删除比较器。
A Tree is sorted keys with associated values. 树是具有相关值的排序键 。 If you want to sort the
QuoteTir
you need a SortedSet of them. 如果要对
QuoteTir
进行排序, QuoteTir
需要它们的SortedSet。
The Constructor which takes a comparator was adding Java 1.2 http://docs.oracle.com/javase/8/docs/api/java/util/TreeMap.html#TreeMap-java.util.Comparator- 带比较器的构造器正在添加Java 1.2 http://docs.oracle.com/javase/8/docs/api/java/util/TreeMap.html#TreeMap-java.util.Comparator-
Check the docs: http://docs.oracle.com/javase/6/docs/api/java/util/TreeMap.html#TreeMap(java.util.Comparator) 检查文档: http : //docs.oracle.com/javase/6/docs/api/java/util/TreeMap.html#TreeMap(java.util.Comparator)
The comparator should compare the keys, not values. 比较器应该比较键,而不是值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.