How to remove duplicate element by using Java 8 feature?

Solution :-

import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;

import java.util.stream.Collectors;

public class DuplicateElement {

public static void main(String[] args) {

List<Integer> list=Arrays.asList(1,1,2,3,3,3,5);

list=list.stream().distinct().collect(Collectors.toList());

System.out.println(list);

}

}

*****************************************************

Leave a Reply

Your email address will not be published. Required fields are marked *

*