4

I found myself using a TreeMap simply because I needed the capability of looking something up with the floorEntry() (and ceilingEntry()) methods. This obviously make the code a bit clumsy. So does anyone happen to know if there is any built-in sorted list that would offer the same functionality as floorEntry()?

So for instance, I have a List<Integer> list. and I have a value int num. I'd like to get the max element in list that is not greater than num

user113454
  • 2,273
  • 9
  • 28
  • 35

1 Answers1

3

Just use a TreeSet, and its floor and ceiling methods, no? Why use a Map?

Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413
  • I believe Louis is right though. That's the most straight-forward answer to your question. – john_science Apr 28 '12 at 01:38
  • Oh, I would use a map as the floor or value key (or data in a Set) is the entry for a dictionary record. e.g, color temperature, rgb value as the dictionary entry. dbm value -> Signal Strength . If you don't need a fast dictionary lookup based onlwm/hwm, than perhaps a map is not the correct choice for you. – Walt Corey Apr 07 '16 at 13:39