Solved

Enforce order in SortedMap

Posted on 2010-11-17
2
222 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
ID: 34159879
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 34159890
> 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet example 11 49
jmss example java 2 23
how to debug htl and js pages 8 39
Tagging and Merging on Branch 1 30
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

829 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