I am using Set Interface for removing duplicate elements from List Interface,Because,List allow Duplicate Elemens also.So,list elements are added to Set interface ,then remove duplicates(not allow Duplicates).

Program:

public class RemoveArrayListDuplicateElements {
    public static void main(String[] args) {
       
        ArrayList list=new ArrayList();
        list.add(4);
        list.add(1);
        list.add(5);
        list.add(9);
        list.add(4);
       
        System.out.println("After  list allowed Duplicates is : "+list);
        HashSet set=new HashSet(list);

        System.out.println("after elements list is : "+set);
       
    }
   
}


Next
This is the most recent post.
Older Post

0 comments:

Post a Comment