Results 1 to 3 of 3

Thread: String keys for arrays

  1. #1
    Join Date
    Dec 2003
    Posts
    115
    Rep Power
    0

    Default String keys for arrays

    I know that Hastable, HashSet, HashMap are some of the classes that support having string keys to store data like arrays. The thing is that these classes don't support (if I'm not mistaken) a multi dimensional type of behavior.

    What I would have love to be able to do is to put a hashMap in another HashMap, but that doesn't seem possible.

    Can anybody direct me to a java class that would give a two dimensional type of feel, with String keys, that can have objects as values.

  2. #2
    Join Date
    Dec 2002
    Posts
    500
    Rep Power
    0

    Default

    what version of java are you using, you need to read up on generics. thats just a head start, seeing that you posted this on the net... google it.

    but if u lazy... just simulate it

    Code:
    public void setGroupMember( string groupName, string course, Person groupMember )
    {
    	return (Person) this.m_hashTable.put( groupName + "`" + course, groupMember );
    }
    
    public Person getGroupMember( string groupName, string course )
    {
    	return (Person) this.m_hashTable.get( groupName + "`" + course );
    }
    or more like
    Code:
    public class GroupMemberMap
    {
    	private HashTable m_hashTable = new HashTable();
    
    	public void put( string groupName, string course, Person groupMember )
    	{
    		return (Person) this.m_hashTable.put( groupName + "`" + course, groupMember );
    	}
    
    	public Person get( string groupName, string course )
    	{
    		return (Person) this.m_hashTable.get( groupName + "`" + course );
    	}
    	...
    	...
    }
    Last edited by icymint3; Aug 3, 2007 at 11:42 AM.
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

  3. #3
    Join Date
    Sep 2005
    Posts
    55
    Rep Power
    0

    Default

    You can put maps, lists and any other object into another map!

    Did you try?

Posting Permissions

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