Last active
August 29, 2015 14:00
-
-
Save ko-sasaki/11346726 to your computer and use it in GitHub Desktop.
Java8-lambda basic 1 -
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sampleJava; | |
import java.util.ArrayList; | |
public class SampleStream { | |
public static void main(String[] args) { | |
ArrayList<String> list = new ArrayList<>(); | |
list.add("a0"); | |
list.add("a1"); | |
list.add("b0"); | |
list.add("b1"); | |
java7(list); | |
java8(list); | |
} | |
public static void java7(ArrayList<String> list){ | |
System.out.println("java7"); | |
for (String string : list) { | |
if(string.startsWith("a")){ | |
System.out.println(string); | |
} | |
} | |
} | |
public static void java8(ArrayList<String> list){ | |
System.out.println("java8"); | |
list.stream() | |
.filter(e -> e.startsWith("a")) | |
.forEach(e -> System.out.println(e)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment