List拷贝和倒序
List<String> sayers = new ArrayList<>();//pop用 sayers.add("钱途"); List<Map<String, Object>> chatsDown = new ArrayList<>(chats);//拷贝 Collections.reverse(chatsDown);//倒序 for (int i = 0; i < chatsDown.size(); i++) { Map<String, Object> map = chatsDown.get(i); String name = map.get("userName") + ""; if (!sayers.contains(name)) { sayers.add(name); } if (sayers.size() >= 6) { //只选6个 break; } }
以前的是程序员的老板,现在是末路出家的程序员小白。