Skip to content

Instantly share code, notes, and snippets.

@YukiYoshikawa
Created April 23, 2013 03:42
Show Gist options
  • Save YukiYoshikawa/5440697 to your computer and use it in GitHub Desktop.
Save YukiYoshikawa/5440697 to your computer and use it in GitHub Desktop.
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