I am implementing TreeMap and I have 2 String Keys one is "304000" and the other is "1026994". I thought the ordering of the key should be "304000", "1026994". But when I step through the debugger, I am seeing "1026994" as the first key. Can someone enlighten me please?
The String comparison doesn't see two numerical values, one of which is larger. It sees two sequences of characters. It compares them, index by index. It sees that '1' comes before '3', so that element is placed ahead of the other in the sort.