Last active
December 16, 2015 07:59
-
-
Save YukiYoshikawa/5402525 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
package trial.yy.java8.client.stream; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
/** | |
* Java8 java.util.stream.Stream#map を試すためのサンプル | |
* User: yy | |
* Date: 13/04/16 | |
* Time: 22:44 | |
*/ | |
public class Java8MapClient { | |
public static void main(String[] args) { | |
// 操作対象の文字列を格納したList | |
List<String> srclist = Arrays.asList("abc", "abcde", "defg", "x", "xyz", "zzzzzzzz"); | |
// 文字列Listの中の各文字列のlengthを新しいListに格納する | |
List<Integer> destList1 = | |
srclist.stream().map(e -> e.length()).collect(Collectors.<Integer>toList()); | |
// 文字列Listの中の各文字列とlengthを新しいListに格納する | |
List<String> destList2 = | |
srclist.stream().map(e -> e + " : " + e.length()).collect(Collectors.<String>toList()); | |
// 結果(新しいList)の内容をまとめて出力 | |
System.out.println("destList1: " + destList1); | |
System.out.println("destList2: " + destList2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment