Hashmap or arraylist

Discussion in 'Plugin Development' started by ChromeHD__, Jul 5, 2014.

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

    ChromeHD__

    I am making a team plugin and i was wondering what would i be better using a hashmap or arraylist i have never used hashmaps before

    I had a problem with the arraylist that it wouldnt remove the players name
     
  2. Offline

    EnchantedMiners

    i am pretty sure both does almost the same thing just that HashMap don't remove the player when they leave HashMap only get cleared when the server reload or close, ArrayLists are useful for quick things and make sure you save the player.getname() not just player because if you save just player then when you try removing player.getname i believe it will send a error hope i helped :p
     
  3. Offline

    ChromeHD__

    i used blue.add(p.getName());
    and blue.remove(p.getName());

    and there is no error
     
  4. Offline

    EnchantedMiners

    ChromeHD__
    sorry for not tagging you in the last post, anyways i have no idea why is not removing it it should doe but i am pretty sure there is other methods of removing players from arraylists.


    Edit: Also may i join dat baddass team xD ?
     
  5. Offline

    Rocoty

    EnchantedMiners Neither a HashMap nor an ArrayList will remove anything unless done explicitly.

    ChromeHD__ They are used for different purposes. An ArrayList - or a List - is used to store an arbitrary amount of data all of the same kind. The data entries are indexed by numbers. A HashMap on the other hand - or a Map - is used for storing data associated with keys, so that data can easily be retrieved using its corresponding key.

    Basically, it depends on what you need to do. If you are planning on dividing players into two teams then two Lists may be the better choice. However, for more teams you might want to consider using a HashMap to store Players as keys and Team names/enum constants as values.
     
  6. Offline

    EnchantedMiners

    Rocoty
    thats a better explanation :D
     
  7. Offline

    augustt198

    wat.

    First of all, no Java Collection will just arbitrarily remove elements.
    Second, all in memory data in your plugin will be reset after a server reload or shutdown.
    Third, trying to remove a Player object from a Collection by using a player's name won't work as they are different types (unless you have a collection of objects ._.)
     
Thread Status:
Not open for further replies.

Share This Page