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;
                                }
                            }

 

posted @ 2021-10-01 12:54  风肖肖(肖遥)  阅读(50)  评论(0编辑  收藏  举报