Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

key-value pair , with key as primitive data type

Thread view: 
studentoflife77@gmail.com - 16 Nov 2007 00:48 GMT
a little primitive question

I am looking to create a key-value pairs (map, table, etc) where the
key should be a primitive data type like int, long ,etc. My keys can
have high numbers

Hashmap, hashtable and all the other collections need Object as key

I can use array but because high key numbers it won't be memory
efficient
e.g: if i have a key of 10005 then the array has to be of the minimum
size 10005 so that i can store my value at array[10005] and later
access it directly

any thoughts?

Student
Daniel Pitts - 16 Nov 2007 01:10 GMT
> a little primitive question
>
[quoted text clipped - 13 lines]
>
> Student
You can use a primitive wrapper class as the key
Map<Integer, String> map = new HashMap<Integer, String>();

With auto-boxing, you can do stuff like:

map.put(10, "Hello");
map.put(20, "Go to 10");

Alternatively, you can create your own implementation of a primitive
keyed map, but I wouldn't suggest it.
Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.