Results 1 to 3 of 3
  1. #1
    Tombomb is offline Member
    Join Date
    Jan 2012
    Posts
    33
    Rep Power
    0

    Question Another HashMap question! yaaay! :P

    Okay, so in my last post about HashMaps I asked what they were for and then if I could save data through application uses. I have since learned how to use a HashMap fairly well, and also learned the serialization process and so forth. But, with what I am trying to do I need a nested HashMap, and I am having trouble figuring out how to make and work it.

    What my program does is this: Program starts, user enters project name along with some measurements. Then, it goes to the next screen with a JComboBox with options "Single Door" and "Double Door". User fills in the measurements for that specific door, and clicks "Next Door". The program then is supposed to serialize the object.

    My problem is this: I need to be able to access the Project Name( first HashMap's Key ), then from there it needs to access a specific door number, which will then lead me to the object. The code I have written to show this is as follows, and it gives no errors. But I don't know how to HashMap.put() and HashMap.get( Key ) to retrieve or put information into the maps.

    Java Code:
    HashMap myMap = new HashMap < String, HashMap < Integer, ProjectName > >();
    I have looked through many forums and all over youtube, but there is nothing about nested HashMaps that helped solve my issue. I did find a couple sites but they weren't able to lead me to an answer, so any help is greatly appreciated!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default Re: Another HashMap question! yaaay! :P

    Looks to me like you;re attempting to use a HashMap in place of a real class.
    I'd say you want a Project class, or something along those lines.
    Model it properly and it'll be a lot easier that messing around with Maps.
    You might end up with a Map<String, Project> in order to get at Projects via their name, but that's still easier than Maps of Maps of Maps.

  3. #3
    Tombomb is offline Member
    Join Date
    Jan 2012
    Posts
    33
    Rep Power
    0

    Default Re: Another HashMap question! yaaay! :P

    Well, I have a Project Name, which is set for the whole job and creates a directory with that name, then inside of the directory it creates a file for each door you create, and I need to be able to get access to each door file inside of each directory. Is there a better way of doing that than serializing maps?


    Okay, this thread can be closed...You were 100% right, I just got rid of the ProjectName class ( which was acting as the "middle man" for transferring data ) and started using just the Cabinet class and it's working flawlessly!! THANK YOU!
    Last edited by Tombomb; 01-19-2012 at 08:51 PM.

Similar Threads

  1. Help with HashMap
    By d0nmin0 in forum Advanced Java
    Replies: 8
    Last Post: 08-15-2011, 01:25 AM
  2. final HashMap hm=new HashMap();
    By sangramkeshari.jena in forum New To Java
    Replies: 4
    Last Post: 07-21-2011, 09:44 PM
  3. Replies: 7
    Last Post: 12-08-2009, 07:17 PM
  4. HashMap question
    By new_2_java in forum New To Java
    Replies: 29
    Last Post: 10-21-2008, 04:27 PM
  5. Hashmap
    By dirtycash in forum New To Java
    Replies: 5
    Last Post: 12-03-2007, 02:58 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
  •