Sunday, November 18, 2018

You can use the Stream.distinct() method to remove duplicates from a Stream in Java 8 and beyond.

  • The distinct() method belongs to class.
  • The distinct() method represent an intermediate Stream operation which means it returns a new Stream without duplicates.
  • Like other stream methods, distinct is also lazy and will not start working unless you call a terminal method.