How to put a hashmap in a hashmap

Discussion in 'Plugin Development' started by Fiddy_percent, Aug 4, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Fiddy_percent

    How do you make a Hashmap inside a Hashmap?
     
  2. Offline

    aufdemrand

    Should be something like this:
    Map<Object, HashMap<Object, Object>> inceptionMap = new HashMap<Object, HashMap<Object, Object>>();
     
  3. Offline

    marwzoor

    Hashmapception :O
     
    WarmakerT and ZeusAllMighty11 like this.
  4. Offline

    Phinary

    Why would you ever need to put a hashmap inside of a hashmap lol.

    Just create your own object and use that inside the hashmap. So much easier and can store more data.
     
    Derthmonuter likes this.
  5. Offline

    Bavestry

    aufdemrand
    That's pretty awesome ;)

    (nobody saw that fail...) lol
     
  6. Offline

    Taco

    This. If you need to store more than two variables together, you may aswell make another class and have that store variables. You can then put the object from that class into a HashMap or List.
     
  7. Offline

    Fiddy_percent

    because Im making a plugin where players can send points to another player so

    Bob: /give jill 10 points
    Jill /give Bob 15 points

    and I want them to be able to look up there history of points given to and from another player
    so bob sees he gave jill 10 points and jill has given him 15 and maybe Jack has given him 5 but he has given jack 0
     
  8. You can just use a custom class then, if you'll only search by sender, you store the sender as key and then in the custom class store the reciever's name and the amount sent.

    Code:
    HashMap<String, SentPoints> = new HashMap<String, SentPoints();
    
    // ...
    
    public class SentPoints
    {
        private String reciever;
        private int points;
    
        public SentPoints(String reciever, int points)
        {
             this.reciever = reciever;
             this.points = points;
        }
    
        // also make getters for reciever and points or just make the variables public and use them directly
    }
     
  9. Offline

    Phinary

    Yeah, use a seperate class to store all the data, then you can just create new instances of it for different players. It will help you much more farther down the road when/if you try to add more functionality.
     
Thread Status:
Not open for further replies.

Share This Page