Last active
May 15, 2018 04:10
-
-
Save sathishjayapal/42b646b07f79b3e697909149ea27ae1f to your computer and use it in GitHub Desktop.
TakeWhile sample
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 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); | |
} | |
} |
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
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The sample for takeWhile in Java 9.