How do I remove repeated elements from ArrayList?

后端 未结 30 1612
难免孤独
难免孤独 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:36

    import java.util.*;
    class RemoveDupFrmString
    {
        public static void main(String[] args)
        {
    
            String s="appsc";
    
            Set unique = new LinkedHashSet ();
    
            for(char c : s.toCharArray()) {
    
                System.out.println(unique.add(c));
            }
            for(char dis:unique){
                System.out.println(dis);
            }
    
    
        }
    }
    

提交回复
热议问题