How to remove duplicate element by using Java 8 feature?

 How to remove duplicate element by using Java 8 feature?

Example :

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);


}


}

****************************************************************************
OutPut :

[1, 2, 3, 5]

Comments

Popular posts from this blog

What are POJO classes in spring? What is the use of POJO Class, and How to create POJO classes.

How to create React project using command prompt?