Java Streams - Stream distinct() example

Stream distinct() returns a stream consisting of the distinct elements according to Object.equals(Object).


distinct has the following syntax.

Stream<T> distinct()


The following example shows how to use distinct.

import java.util.Arrays;
import java.util.List;
/*from   w  w  w  . j  ava  2  s  .c  om*/
public class Main {
  public static void main(String[] args) {
    List<String> stringList = Arrays.asList("1","1","2","3","4");

The code above generates the following result.