美文网首页
去掉List对象列表中重复的bean

去掉List对象列表中重复的bean

作者: 程序设计法师 | 来源:发表于2019-05-06 11:26 被阅读0次
  PlayListLiveData.getInstance().observe(this, new Observer<List<SongInfo>>() {
            @Override
            public void onChanged(@Nullable List<SongInfo> songInfos) {
                List<Integer> integerList=new ArrayList<>();
                if(songInfos!=null&&songInfos.size()>0) {
                    for (int i = 0; i <= songInfos.size() - 1; i++) {
                        for (int j = i + 1; j <= songInfos.size() - 1; j++) {
                            if (songInfos.get(i).getSong_id() == songInfos.get(j).getSong_id()) {
                                integerList.add(i);
                            }
                        }
                    }
                }
                if(integerList.size()>0) {
                    for (int i = 0; i < integerList.size(); i++) {
                        songInfos.remove(songInfos.get(integerList.get(i)));
                    }
                }
                adapter.clear();
                adapter.addAll(songInfos);
            }
        });

相关文章

网友评论

      本文标题:去掉List对象列表中重复的bean

      本文链接:https://www.haomeiwen.com/subject/gekroqtx.html