Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Liutauras Vilda
Ron McLeod
Jeanne Boyarsky
Paul Clapham
Sheriffs:
Junilu Lacar
Tim Cooke
Saloon Keepers:
Carey Brown
Stephan van Hulst
Tim Holloway
Peter Rooke
Himai Minh
Bartenders:
Piet Souris
Mikalai Zaikin
Forum:
Java in General
reading elements in hashtable in an order
sitaram irrinki
Ranch Hand
Posts: 158
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
By default, Hashtable is unordered. Then, how can you retrieve Hashtable
elements in the same order as they are put inside
Tony Morris
Ranch Hand
Posts: 1608
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.util.Map; import java.util.LinkedHashMap; final class X { private X() throws UnsupportedOperationException { throw new UnsupportedOperationException(); } public static void main(final String... args) { final Map<String, String> m = new LinkedHashMap<String, String>(); m.put("a", "b"); m.put("b", "c"); m.put("c", "d"); // guarantees output a b c for(String key : m.keySet()) { System.out.println(key); } } }
Tony Morris
Java Q&A (FAQ, Trivia)
Don't destroy the earth! That's where I keep all my stuff! Including this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to keep the order of elements in hashtable
Hashtable
Sorting hashtable entries
ordering Hashtable elements
how to prove that Hashtable is not ordered
More...