标签:多线程并发 min set 删除 key class ogg user list
删除List中指定的元素
CopyOnWriteArrayList是ArrayList的一个线程安全的变体实现,即可在多线程并发环境中使用
List<Map<String, Object>> allUsers = (List<Map<String, Object>>) userService.getAllUsers().get("allUser"); CopyOnWriteArrayList allUser = new CopyOnWriteArrayList(allUsers); Iterator<Map<String, Object>> iter = allUser.iterator(); while (iter.hasNext()) { Map<String, Object> map = iter.next(); Iterator<Map.Entry<String, Object>> iterSub = map.entrySet().iterator(); while (iterSub.hasNext()) { Map.Entry entry = iterSub.next(); if(entry.getKey().equals("username")){ logger.info("username: " + entry.getKey()); if (entry.getValue().equals("admin")){ logger.info("admin: " + entry.getValue()); allUser.remove(map); } } } } logger.info("allUser: " + allUser);
标签:多线程并发 min set 删除 key class ogg user list
原文地址:http://www.cnblogs.com/denied/p/6898514.html