How do I remove repeated elements from ArrayList?

后端 未结 30 1738
难免孤独
难免孤独 2020-11-21 06:24

I have an ArrayList, and I want to remove repeated strings from it. How can I do this?

30条回答
  •  后悔当初
    2020-11-21 06:52

    If you want to preserve your Order then it is best to use LinkedHashSet. Because if you want to pass this List to an Insert Query by Iterating it, the order would be preserved.

    Try this

    LinkedHashSet link=new LinkedHashSet();
    List listOfValues=new ArrayList();
    listOfValues.add(link);
    

    This conversion will be very helpful when you want to return a List but not a Set.

提交回复
热议问题