Last active
November 17, 2016 12:48
-
-
Save kasecato/193e9038d336f6ea7ac2 to your computer and use it in GitHub Desktop.
Java 9 Streamに追加された3つの新機能 ref: http://qiita.com/k--kato/items/64967d2555f39aace608
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
// arrange | |
List<Integer> list = Arrays.asList(0, 1, 2, -1, 2); | |
// act | |
Predicate<Integer> p = (x) -> x <= 1; | |
boolean isDirty = false; | |
for (Integer x : list) { | |
if (!isDirty && p.negate().test(x)) isDirty = true; | |
if (isDirty) System.out.println(x); | |
} | |
// 2 | |
// -1 | |
// 2 | |
long skipIndex = list.indexOf(list.stream().filter(p.negate()).findFirst().get()); | |
list.stream().skip(skipIndex).forEach(System.out::println); | |
// 2 | |
// -1 | |
// 2 |
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
// arrange | |
List<Integer> list = Arrays.asList(0, 1, 2, -1, 2); | |
// act | |
list.stream().dropWhile(x -> x <= 1).forEach(System.out::println); | |
// 2 | |
// -1 | |
// 2 |
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
// arrange | |
List<Integer> list = Arrays.asList(0, 1, 2, -1, 2); | |
// act | |
for (Integer x : list) { | |
if (x <= 1) System.out.println(x); | |
else break; | |
} | |
// 0 | |
// 1 |
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
// arrange | |
List<Integer> list = Arrays.asList(0, 1, 2, -1, 2); | |
// act | |
list.stream().takeWhile(x -> x <= 1).forEach(System.out::println); | |
// 0 | |
// 1 |
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
// arrange | |
List<String> list = Arrays.asList("Angular", "ES7", "React"); | |
Map<String, Integer> map = new HashMap<String, Integer>() { | |
{ | |
put("Angular", 1); | |
put("ES2016", 2); | |
put("React", 3); | |
} | |
}; | |
// act | |
list.stream().flatMap(str -> { | |
Integer temp = map.get(str); | |
return (temp != null) ? Stream.of(temp) : Stream.empty(); | |
}).forEach(System.out::println); | |
// 1 | |
// 3 |
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
// arrange | |
List<String> list = Arrays.asList("Angular", "ES7", "React"); | |
Map<String, Integer> map = new HashMap<String, Integer>() { | |
{ | |
put("Angular", 1); | |
put("ES2016", 2); | |
put("React", 3); | |
} | |
}; | |
// act | |
list.stream().flatMap(str -> Stream.ofNullable(map.get(str))).forEach(System.out::println); | |
// 1 | |
// 3 |
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
Error:Abnormal build process termination: | |
エラー: メイン・クラスorg.jetbrains.jps.cmdline.Launcherが見つからなかったかロードできませんでした |
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
Error:java: invalid flag: -release |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment