Solved

Enforce order in SortedMap

Posted on 2010-11-17
2
219 Views
Last Modified: 2012-05-10
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?


0
Comment
Question by:allelopath
  • 2
2 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
> 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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now