Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sathishjayapal/42b646b07f79b3e697909149ea27ae1f to your computer and use it in GitHub Desktop.
Save sathishjayapal/42b646b07f79b3e697909149ea27ae1f to your computer and use it in GitHub Desktop.
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)
.map(String::toUpperCase).forEach(System.out::println);
}
}
package Song;
public class Song {
private String name;
private int albumYear;
private String genre;
public String getName() {
return name;
}
public void setName(String name) {
this.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.name=name;
this.albumYear=albumYear;
this.genre=genre;
}
}
@sathishjayapal
Copy link
Author

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