Results 1 to 7 of 7
  1. #1
    jklsemicolon is offline Member
    Join Date
    Aug 2008
    Posts
    15
    Rep Power
    0

    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?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,398
    Rep Power
    25

    Default

    Yes. There are many ways to store data. Can you describe your problem in more detail.

  3. #3
    jklsemicolon is offline Member
    Join Date
    Aug 2008
    Posts
    15
    Rep Power
    0

    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.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,398
    Rep Power
    25

    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.

  5. #5
    jklsemicolon is offline Member
    Join Date
    Aug 2008
    Posts
    15
    Rep Power
    0

    Default

    How would I go about making a multidimensional array of objects?

    object[][] arrayName = new object[3][10];

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  7. #7
    jklsemicolon is offline Member
    Join Date
    Aug 2008
    Posts
    15
    Rep Power
    0

Similar Threads

  1. Replies: 9
    Last Post: 06-25-2008, 04:48 AM
  2. how can we get the element of by using the hashtable
    By raj reddy in forum Web Frameworks
    Replies: 1
    Last Post: 05-06-2008, 01:45 PM
  3. Hashtable example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-15-2008, 08:43 AM
  4. Hashtable-put method
    By new_1 in forum New To Java
    Replies: 1
    Last Post: 12-23-2007, 07:07 PM
  5. Multidimensional arrays
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-05-2007, 05:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •