Java streams 16. Filtering, Skipping, Sorting

Stream.of("2", "4", "3", "4", "2")
.distinct()
.forEach(System.out::print); //prints: 243
Stream.of("2", "4", "3", "4", "2")
.filter(s -> Objects.equals(s, "2"))
.forEach(System.out::print); //prints: 22
Stream.of("2", "4", "3", "4", "2")
.dropWhile(s -> Integer.valueOf(s) < 3)
.forEach(System.out::print); //prints: 4342
Stream.of("2", "4", "3", "4", "2")
.takeWhile(s -> Integer.valueOf(s) < 3)
.forEach(System.out::print); //prints: 2
Stream.of("2", "4", "3", "4", "2")
.skip(3)
.forEach(System.out::print); //prints: 42
Stream.of("2", "4", "3", "4", "2")
.limit(3)
.forEach(System.out::print); //prints: 243
Stream.of("2", "4", "3", "4", "2")
.sorted().forEach(System.out::print); //prints: 22344
Stream.of("2", "4", "3", "4", "2")
.sorted(Comparator.reverseOrder())
.forEach(System.out::print); //prints: 44322

--

--

--

Born in Moscow, lived in Crimea, now lives in the US. Used to be physicist and rock climber, now programmer and writer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Using Indirect Multipliers

Web Crawling with Beautifulsoup — Advance

Life after FlatIron School

Flutter and Sprite Widget

How i Hacked into European Union Website

ASM Helps the Young Generation Fall in Love over Social Media by Accelerating Application Mesh…

The Latest

BRTechnosoft is leading Web Development (PHP, Magento, Nodejs, Angularjs, NodeJS, Shopify 5, Wordpress, Laravel, eCommerce, Dot.net) Company based India, Web Design, Mobile Application (iPhone, Android, iPad), Best SEO Company India

A few PHP developers in a Java World

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nick Samoylov

Nick Samoylov

Born in Moscow, lived in Crimea, now lives in the US. Used to be physicist and rock climber, now programmer and writer.

More from Medium

Java record: A Brief

Regular Expressions in Java

Applying Functional Programming Concept on Classes and Methods

How To Format A String in Java