Created
April 27, 2014 14:26
-
-
Save ko-sasaki/11346888 to your computer and use it in GitHub Desktop.
Java8-lambda basic 2 -
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 (int i = 0; i < 3 ; i++){ | |
System.out.println(list.get(i)); | |
} | |
} | |
public static void java8(ArrayList<String> list){ | |
System.out.println("java8"); | |
list.stream() | |
.limit(3) | |
.forEach(System.out::println); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment