GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing raw.githubusercontent.com — raw.githubusercontent.com

import java.util.List; import java.util.stream.Collectors; /* A demo for the Java Streams API Includes examples with lists of numbers and words */ public class JavaStreams { private static final List numbers = List.of(10, 2, 21, 23, 22, 14, 16, 18, 19, 9, 4, 6, 7); private static final List words = List.of("apple", "bread", "tree", "computer", "name", "brain", "arm"); //Use stream to find all numbers that are greater than 10 public static List findAllNumbersGreaterThanTen(List numbers){ return numbers.stream() .filter(number -> number > 10) .sorted() .collect(Collectors.toList()); } //Use stream to find all numbers that contain the letter a public static List findAllWordsThatContainLetterA(List words){ return words.stream() .filter(word -> word.contains("a")) .collect(Collectors.toList()); } //print out the origin lists, and then the changed lists public static void main(String[] args) { System.out.println("The unsorted array is: " + numbers); System.out.println("The sorted array is: " + numbers.stream().sorted().toList()); System.out.println("All numbers in the list greater than 10: " + findAllNumbersGreaterThanTen(numbers)); System.out.println(); System.out.println("A list of words: " + words); System.out.println("All words in the list that contain the letter A: " + findAllWordsThatContainLetterA(words)); } }
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.