HashMap, Map, and ArrayList

Discussion in 'Programming' started by Waldxn, Apr 25, 2017.

  1. Anywhere to actually learn about these (methods?)

    Not the typical oracle tutorials, I'd like to see a more simplified/noob friendly tutorials.
     
  2. Hash map is a key/value setup.

    The key is unique while values can be duplicated.
    For example
    HashMap<Player,Integer> playerKills

    When a player kills something.
    Int kills = playerKills.get(plr);
    playerKills.put(plr,kills +1);

    Array lists are single dimensional, meaning it's just a list of objects.

    List<ItemStack> items = new ArrayList<ItemStack>();

    for(ItemStack is:plr.getInventory())
    Items.add(is);

    Now you have a list of items that you can do stuff with.

    Map<K,V> is an interface, HashMap<K,V> is a class that implements Map.





    Sent from my iPhone using Tapatalk
     

  3. Thank you! Do you know of anyway I can practice this? I may start with HashMaps but I would like an info source or somewhere to start :)
     
  4. WAS

    WAS

    Just check them out in your IDE, or use an online one if it's somehow a hassle.
     
  5. Well unless you're just writing really simple java programs this information may not be of much use to you, it takes a lot of code to get a plugin up and running before you can make much use of hashmaps and lists.

    Knowing java helps but the spigot API has its own set of rules and quirks that give it its very own learning curve.


    Sent from my iPhone using Tapatalk
     
  6. That's fair. Thanks for the help though!
     
  7. Would these be useful for setting up a sort of party system?
     
    • Agree Agree x 1
  8. Sure, you could create a custom party class that inside had a set for members, an object for the party leader or whatever else you wanted.

    Then a Set<Party> = new HashSet<Party>();
    (Hash set is like a list but has no set order and only contains unique values. )

    And you could add your new Party(); object to it to track the active parties.

    Or a simpler method might be
    HashMap<Player,List<Player>> parties

    Where player is the leader of the party and the list contains the party members.


    Sent from my iPhone using Tapatalk
     
  9. WAS

    WAS