Hey Bukkit, i'm here having some difficulties, i'm trying to divide an HashMap of players into 2 teams(different hashmaps), i used this method using ArrayList's but in this case i need to use HashMap. So i have these 3 HashMaps: Code:java public static Map<Game, String> in_lobby = new HashMap<Game, String>(); public static Map<Game, String> on_red = new HashMap<Game, String>(); public static Map<Game, String> on_blue = new HashMap<Game, String>(); I want to divide the in_lobby HashMap into the red team and the blue team, i have this code, but subList's are only for ArrayList's, so how would i do it with the HashMap ? Code:java if(in_lobby.size() > 0){ on_red.putAll(in_lobby.subList(0, in_lobby.size() / 2 + in_lobby.size()%2)); on_blue.putAll(in_lobby.subList(in_lobby.size() / 2 + in_lobby.size()%2, in_lobby.size())); in_lobby.clear(); }
BugsyFTW Why not add them first to a list, divide that list in 2, and then add them to the hashmap they belong to?
Why not make Game contain a method called getTeam() that returns a team enum? Then you can loop through the map and check if the player is on red team or blue team.
BugsyFTW Just put all the players in a list, divide the list in 2, put one half in the on_red map and the other galf in the on_blue map.
BugsyFTW Try this: for(Player player : Bukkit.getOnlinePlayers()){ boolean b = false; if(b){ //put in red b = false; }else{ //put in blue b = true; } }