Data structures that can map a range of keys to a value

Are your ranges non-overlapping? If so you could use a TreeMap: TreeMap<Double, Character> m = new TreeMap<Double, Character>(); m.put(1.0, ‘A’); m.put(2.9, null); m.put(4.0, ‘B’); m.put(6.0, null); m.put(6.5, ‘C’); m.put(10.0, null); The lookup logic is a bit complicated by the fact that you probably want an inclusive lookup (i.e. 2.9 maps to ‘A’, and not undefined): … Read more