Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-16-2008, 05:30 AM
Member
 
Join Date: Aug 2008
Posts: 15
Rep Power: 0
jklsemicolon is on a distinguished road
Default Multidimensional hashtable?
I am trying to store objects ints and Strings together so that they are easily accessable, something like a multidimensional array, but with different data types like a hashtable, in a way. Is there a way I could do that?
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 08-16-2008, 02:44 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
Yes. There are many ways to store data. Can you describe your problem in more detail.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-17-2008, 01:47 AM
Member
 
Join Date: Aug 2008
Posts: 15
Rep Power: 0
jklsemicolon is on a distinguished road
Default
Mk perhaps I have an unknown number of people connecting to a server with a name, an age as an int and a socket connection. I want to store them all in something like an array or a hashtable so I can do a for each or an enumeration for them, but an array only holds one type of data and a hashtable only can store two things.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-17-2008, 03:38 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
How do you want to access the data? By key then a hash, by index then an array.
You can have an array of objects. An object can hold any combination of data.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-17-2008, 06:02 AM
Member
 
Join Date: Aug 2008
Posts: 15
Rep Power: 0
jklsemicolon is on a distinguished road
Default
How would I go about making a multidimensional array of objects?

object[][] arrayName = new object[3][10];
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 08-17-2008, 06:08 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,447
Rep Power: 8
Fubarable is on a distinguished road
Default
Quote:
How would I go about making a multidimensional array of objects?
As Norm is suggesting, you really don't want to do this. You'll be far better off creating a class that holds your name String, age int, and any other pertinent objects, and then have a single dimensional array (or HashMap if need be) that holds objects of the new class's type.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 08-17-2008, 06:23 AM
Member
 
Join Date: Aug 2008
Posts: 15
Rep Power: 0
jklsemicolon is on a distinguished road
Default
Thanks I'll try that
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

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

BB 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
Make Java codes more simplier (Multidimensional Arrays) javanewbie JCreator 9 06-25-2008 05:48 AM
how can we get the element of by using the hashtable raj reddy Web Frameworks 1 05-06-2008 02:45 PM
Hashtable example Java Tip Java Tips 0 02-15-2008 09:43 AM
Hashtable-put method new_1 New To Java 1 12-23-2007 08:07 PM
Multidimensional arrays Java Tip Java Tips 0 11-05-2007 06:07 PM


All times are GMT +2. The time now is 03:02 AM.



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