Last active
February 20, 2016 11:23
-
-
Save activestudy/f42e64dab2c6eb21c349 to your computer and use it in GitHub Desktop.
This file contains 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
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* | |
* @author NguyenHaiDang@ActiveStudy | |
*/ | |
public class StreamTest { | |
public static void main(String[] args) { | |
List<Person> people = new ArrayList<>(); | |
people.add(new Person(18, "Joe")); | |
people.add(new Person(20, "Jack")); | |
people.stream() | |
.map(p -> p.getAge()) //map tuổi của person | |
.peek(System.out::println) //in ra màn hình bằng lệnh peek(), mục đích để debug | |
.filter(age -> age < 20) //filter các person có tuổi nhỏ hơn 20 | |
.forEach(System.out::println); //in ra màn hình tuổi sau khi đã filter | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment