Results 1 to 4 of 4
  1. #1
    sopna sajith is offline Member
    Join Date
    Jun 2008
    Posts
    2
    Rep Power
    0

    Default Hastable - Multiple Types

    can a single hashtable contain multiple datatype objects If so please give me an example

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    Thread was moved and I'm sure willing folks will be able to assist momentarily.
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    Read the API doc for Hashtable, especially the put() method.
    What is the datatype for the value?

    ht.put("key", "value");
    ht.put("key2", ht);

  4. #4
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    6

    Default

    @norm has the example. But doing so loses type safety, as you have to not use generics. Depending on your needs, this may be acceptable. Or you can define and use a polymorphic struct/class

Similar Threads

  1. Can I use vectors to store multiple types of objects
    By Nathand in forum Advanced Java
    Replies: 6
    Last Post: 04-28-2008, 07:55 AM
  2. Converting data types
    By bluekswing in forum New To Java
    Replies: 4
    Last Post: 01-12-2008, 12:48 AM
  3. Displaying different image types
    By splinter64uk in forum AWT / Swing
    Replies: 1
    Last Post: 12-05-2007, 08:12 AM

Posting Permissions

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