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

How to create React project using command prompt?

How to achieve abstraction?

Interview Question? How to find square of each element in this Array {2,4,5,6,8} using map ?