Results 1 to 2 of 2
  1. #1
    darkblue24 is offline Member
    Join Date
    Jan 2010
    Posts
    36
    Rep Power
    0

    Default 2D array inside a HashMap

    Hi everyone i would like to know how to access values stored in a 2D array inside a HashMap
    Here is a drawing representation of the map.

    So to get the KEYS I just have to execute this code:

    Java Code:
    this.allPeople = personInterests.keySet();
    But how can I get acces to the actual values inside the 2D Array?

    My goal is to create a treeSet and store all the elements of the first array in it, then look at the second array if any new elements are detected add them to the treeset, then third array and so on.



    I tried this code:

    Java Code:
    Object[] bands = personInterests.values().toArray();
         for( int i=0; i<bands.length; i++)
         {
              this.allBands.add(bands[i].toString());
         }
    But

    Java Code:
    this.allBands.add(bands[i].toString())
    seems to be the problem, Dealing with a 2D array, this code only return a string representation of the Arrays and not a string representation of their elements.

    Using my logic I tried to execute:

    Java Code:
    this.allBands.add(bands[0][i].toString());
    But i get a ARRAY REQUIRED BUT JAVA.LANG.OBJECT FOUND

    I really don't know the way to go.
    Thanks to anyone that will help.

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    It's not really clear from your post where the 2D arrays come into play...

    Object[] bands is a 1-D array, so obviously, when you try to do bands [0][0] you get an error.

Similar Threads

  1. Something like HashMap
    By BigBear in forum New To Java
    Replies: 4
    Last Post: 03-14-2010, 12:08 PM
  2. Replies: 7
    Last Post: 12-08-2009, 08:17 PM
  3. HashMap
    By koolhoney in forum Advanced Java
    Replies: 1
    Last Post: 03-30-2009, 09:08 PM
  4. hashmap
    By tOpach in forum New To Java
    Replies: 2
    Last Post: 09-24-2008, 01:55 PM
  5. string inside of a xml
    By Heather in forum XML
    Replies: 2
    Last Post: 03-28-2008, 06:21 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
  •