[英]How to preserve TreeSet comparator?
假設我使用匿名Comparator
構造TreeSet
,如下所示:
private TreeSet<Counter> mySet =
new TreeSet<Counter>(
new Comparator<Counter>(){
@Override
public int compare(Counter c1, Counter c2) {
// some weird comparison logic here...
}
});
現在我想讓TreeSet
的一部分等於或大於someCounter
,如下所示:
mySet.tailSet(someCounter);
如何使tailSet()
返回的TreeSet
的部分基於構造mySet
的原始比較器,而不是僅獲取按自然順序排序的有序集?
它已經基於您TreeSet
創建TreeSet
的比較器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.