Skip to content

Instantly share code, notes, and snippets.

@activestudy
Last active February 20, 2016 11:23
Show Gist options
  • Save activestudy/f42e64dab2c6eb21c349 to your computer and use it in GitHub Desktop.
Save activestudy/f42e64dab2c6eb21c349 to your computer and use it in GitHub Desktop.
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