Removing Duplicates From ListView android

♀尐吖头ヾ 提交于 2019-12-06 15:36:06

If you don't want to allow duplicate into collection of your object then use the Set object it will now allow the duplicate value.

Set suggestion = new HashSet();

or you can add your list object to this object it will now add duplicate value

ArrayList al = new ArrayList();
// add elements to al, including duplicates
HashSet hs = new HashSet();
hs.addAll(al);
al.clear();
al.addAll(hs);

updated for your case:

use your suggestion object instead of the above al object just it.

You could use that code:

    private static HashSet<String> hs = new HashSet<String>();
    private static ArrayList<String> list= new ArrayList<String>();

    for(int i=0; i<list.size(); i++){
        hs.add(list.get(i));

    }

    list.clear();
    list.addAll(hs);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!