Enforce order in SortedMap

Suppose I have a SortedMap:
SortedMap <String, String> map = new TreeMap<String, String>();

Open in new window

and then I add some values:
   map.put("Mary", "Orange");
   map.put("Bob", "Banana");
   map.put("Jack", "Apple");

Open in new window

It seems that by default, it puts them in alphabetical order.
How would I cause it to put it in order that they are added to the list?


LVL 1
allelopathAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
> How would I cause it to put it in order that they are added to the list?

sorry didn't see that. in which case you're not actaully sorting them
use a LinkedHashMap instead
0
 
objectsCommented:
0
All Courses

From novice to tech pro — start learning today.