Hi, i have been starting on coding plugins and i would like to know what HashMap means and what Itnerator(idk if its this) means too
A HashMap is a collection of objects (like a List), where each element has a corresponding key to it: for example, if I wanted to store a separate integer score per player, I would use a HashMap. The syntax is <key type, value type>, which in this case will be String (player name) and Integer (for their score) - don't use primitive data types like int/boolean/double, use Integer/Boolean,Double: Code: HashMap<String, Integer> scores = new HashMap<String, Integer>(); Add a player and his score: Code: scores.put("Chinwe", 0); scores.put("Pik0", 5); scores.put("Player", 10); Get a player's score: Code: int chinwesScore = scores.get("Chinwe"); An iterator is used for looping through every key/value in a Map, although you can use an enhanced for loop too: Code: // for loop for (String name : scores.keySet()) { // loops through "Chinwe", "Pik0" and "Player" } for (int score : scores.values()) { // loops through 0, 5 and 10 } Iterators are used like this: Code: // make a new iterator, which takes the type of object it will be looping through // in this case, <String> Iterator<String> iterator = scores.keySet().iterator(); // it will loop as long as there are still keys to loop through while (iterator.hasNext()) { String name = iterator.next(); // gets the next name // do your stuff }
Hah, you're bad at this game, only 0 points? NOOB! Nawh I kid, but Pik0 set this thread to Solved please.