JavaSupplier.java
package javasupplier; import java.util.Scanner; import java.util.function.Supplier; import java.util.stream.Stream; public class JavaSupplier { public static void main(String[] args) { Supplier<String> msg = ()-> "http://java-buddy.blogspot.com/"; System.out.println(msg.get()); System.out.println(); Scanner scanner = new Scanner(System.in); Supplier<String> scannerNext = () -> scanner.next(); System.out.println("Enter something, 'q' to quit"); Stream.generate(scannerNext) .map(s -> { System.out.println(s); return s; }) .allMatch(s -> !"q".equals(s)); } }
No comments:
Post a Comment