JPad
Snippets
Download
Help
Contact
new 3
stream
Code
List<String> sl = Arrays.asList("a", "b", "aa"); // -- https://www.tutorialspoint.com/java8/java8_streams.htm // -- https://www.tutorialspoint.com/java8/java8_lambda_expressions.htm // -- https://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/ // -- https://winterbe.com/posts/2014/03/16/java-8-tutorial/ // Stream<String> strings = Stream.of("foo", "bar", "baz"); sl.forEach(System.out::print); System.out.println("\n"); sl.forEach(n -> System.out.print(n + " ")); System.out.println("\n"); sl .stream() .filter((s) -> s.startsWith("a")) .forEach(System.out::println);
Result
Console
abaa a b aa a aa
Bytecode
Compiled from "RunnContainer.java" public class io.jpad.scratch.RunnContainer { public io.jpad.scratch.RunnContainer(); Code: 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String...) throws java.lang.Exception; Code: 0: iconst_3 1: anewarray #2 // class java/lang/String 4: dup 5: iconst_0 6: ldc #3 // String a 8: aastore 9: dup 10: iconst_1 11: ldc #4 // String b 13: aastore 14: dup 15: iconst_2 16: ldc #5 // String aa 18: aastore 19: invokestatic #6 // Method java/util/Arrays.asList:([Ljava/lang/Object;)Ljava/util/List; 22: astore_1 23: aload_1 24: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream; 27: dup 28: invokevirtual #8 // Method java/lang/Object.getClass:()Ljava/lang/Class; 31: pop 32: invokedynamic #9, 0 // InvokeDynamic #0:accept:(Ljava/io/PrintStream;)Ljava/util/function/Consumer; 37: invokeinterface #10, 2 // InterfaceMethod java/util/List.forEach:(Ljava/util/function/Consumer;)V 42: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream; 45: ldc #11 // String \n 47: invokevirtual #12 // Method java/io/PrintStream.println:(Ljava/lang/String;)V 50: aload_1 51: invokedynamic #13, 0 // InvokeDynamic #1:accept:()Ljava/util/function/Consumer; 56: invokeinterface #10, 2 // InterfaceMethod java/util/List.forEach:(Ljava/util/function/Consumer;)V 61: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream; 64: ldc #11 // String \n 66: invokevirtual #12 // Method java/io/PrintStream.println:(Ljava/lang/String;)V 69: aload_1 70: invokeinterface #14, 1 // InterfaceMethod java/util/List.stream:()Ljava/util/stream/Stream; 75: invokedynamic #15, 0 // InvokeDynamic #2:test:()Ljava/util/function/Predicate; 80: invokeinterface #16, 2 // InterfaceMethod java/util/stream/Stream.filter:(Ljava/util/function/Predicate;)Ljava/util/stream/Stream; 85: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream; 88: dup 89: invokevirtual #8 // Method java/lang/Object.getClass:()Ljava/lang/Class; 92: pop 93: invokedynamic #17, 0 // InvokeDynamic #3:accept:(Ljava/io/PrintStream;)Ljava/util/function/Consumer; 98: invokeinterface #18, 2 // InterfaceMethod java/util/stream/Stream.forEach:(Ljava/util/function/Consumer;)V 103: return private static boolean lambda$main$1(java.lang.String); Code: 0: aload_0 1: ldc #3 // String a 3: invokevirtual #19 // Method java/lang/String.startsWith:(Ljava/lang/String;)Z 6: ireturn private static void lambda$main$0(java.lang.String); Code: 0: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream; 3: new #20 // class java/lang/StringBuilder 6: dup 7: invokespecial #21 // Method java/lang/StringBuilder."<init>":()V 10: aload_0 11: invokevirtual #22 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 14: ldc #23 // String 16: invokevirtual #22 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 19: invokevirtual #24 // Method java/lang/StringBuilder.toString:()Ljava/lang/String; 22: invokevirtual #25 // Method java/io/PrintStream.print:(Ljava/lang/String;)V 25: return }
Jpad Version:1.07
viewCount:2217
Creator:
vp
Latest Editor:
vp
Tags
stream
Download
Copy As Markdown:
**code [new 3.java](/example/1Q/new-3)** List
sl = Arrays.asList("a", "b", "aa"); // -- https://www.tutorialspoint.com/java8/java8_streams.htm // -- https://www.tutorialspoint.com/java8/java8_lambda_expressions.htm // -- https://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/ // -- https://winterbe.com/posts/2014/03/16/java-8-tutorial/ // Stream
strings = Stream.of("foo", "bar", "baz"); sl.forEach(System.out::print); System.out.println("\n"); sl.forEach(n -> System.out.print(n + " ")); System.out.println("\n"); sl .stream() .filter((s) -> s.startsWith("a")) .forEach(System.out::println); **Result:** abaa a b aa a aa