Created
April 23, 2013 03:42
-
-
Save YukiYoshikawa/5440697 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; | |
/** | |
* Java8 java.util.stream.Stream#reduce を試すためのサンプル | |
* User: yy | |
* Date: 13/04/16 | |
* Time: 22:44 | |
*/ | |
public class Java8ReduceClient { | |
public static void main(String[] args) { | |
// 操作対象の文字列を格納したList | |
List<String> srclist = Arrays.asList("abc", "abcde", "defg", "x", "xyz", "zzzzzzzz"); | |
// 文字列Listの中の各文字列のlengthの合計を取得してみる | |
int sumLength = | |
srclist.stream().map(e -> e.length()).reduce(0, (sum, i) -> sum + i); | |
System.out.println("sumLength: " + sumLength); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment