Solved

Enforce order in SortedMap

Posted on 2010-11-17
2
223 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
type mismatch (Object[] to double[] 4 41
ejb on wildfly 5 45
Running JavaFX on the Raspberry Pi 27 121
Java Inheritance super keyword use 8 32
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

713 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