简体   繁体   中英

NavigableSet with own object types?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM