Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-20-2007, 11:26 AM
Senior Member
 
Join Date: Nov 2007
Posts: 115
ravian is on a distinguished road
Uisng primitive type values as keys for Hashtable
I have the following code which works fine.

Code:
Hashtable hash = new Hashtable(10,10); int i= 1; hash.put(i, "StringV"); System.out.println(hash.get(i));
I read somewhere that Hashable takes objects as key and primitive types are not allowed as keys. I tried int as key and it worked. Can anyone tell me about this.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-21-2007, 08:16 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Autoboxing in j2se 1.5+ allows this. See this page in the guide in your j2se 1.5 javadocs distribution, or Autoboxing.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-21-2007, 11:50 AM
Senior Member
 
Join Date: Nov 2007
Posts: 115
ravian is on a distinguished road
Thanks. That explains.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-21-2007, 12:13 PM
Member
 
Join Date: Nov 2007
Posts: 1
kash_meu is on a distinguished road
Another Way
Another way to accomplish this can be

hash.put(new Integer(i), "StringV");
System.out.println(hash.get(new Integer(i)));
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing boolean Values of another values in one class. a_iyer20 Advanced Java 4 04-15-2008 03:04 PM
Primitive data types of Java Java Tip Java Tips 0 03-28-2008 09:29 PM
Retreiving list of keys from Map with certan value desmond5 New To Java 1 03-06-2008 10:10 PM
Hashtable example Java Tip Java Tips 0 02-15-2008 10:43 AM
Introduction to Hashtable JavaForums Java Blogs 1 11-20-2007 11:13 PM


All times are GMT +3. The time now is 04:40 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org