Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
TakeWhile sample
import Song.Song;
import java.util.Arrays;
import java.util.List;
public class MainJava9 {
public static List<Song> createSong() {
return Arrays
.asList(new Song("Venilave", 2000, "Rehman"), new Song("Va Va Vasanthame", 2002, "Raja"),
new Song("Vanjokotiya", 2010, "Raja"), new Song("semmaFigure", 2008, "Rehman"),
new Song("Arabic kadloram", 2001, "Rehman"), new Song("Anjali Anjali", 1995, "Raja"),
new Song("Pen alla Pen alla", 2010, "Rehman"));
public static void main(String args[]) {
createSong().stream().takeWhile(song -> song.getAlbumYear() < 2002).peek(song -> System.out.println(song.getAlbumYear())).map(Song::getName)
package Song;
public class Song {
private String name;
private int albumYear;
private String genre;
public String getName() {
return name;
public void setName(String name) { = name;
public int getAlbumYear() {
return albumYear;
public void setAlbumYear(int albumYear) {
this.albumYear = albumYear;
public String getGenre() {
return genre;
public void setGenre(String genre) {
this.genre = genre;
public Song(String name, int albumYear, String genre){;

This comment has been minimized.

Copy link
Owner Author

@sathishjayapal sathishjayapal commented May 15, 2018

The sample for takeWhile in Java 9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment