How can I use tailSet()
and headSet()
for a NavigableSet<MyType>
? And also implement own rules which elements would qualify for a tailset or headset?
Like:
class MyType {
String name;
String number;
}
Now if I have a type("daniel", "12"), I want to have all elements which are alphabetically before daniel, and number > 12. This would be my headset. The opposite would be the tailset. (of course the comparisions do not make any sense, but you get what I'm trying to do).
让MyType
实现Comparable
或使用NavigableSet
,让您提供单独的Comparator
例如TreeSet
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.