Created
January 29, 2015 07:29
-
-
Save danialgoodwin/b05407bd9649d835d5f1 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
public class Sample { | |
public static void main(String[] args) { | |
List<Integer> values = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9); | |
int result = 0; | |
for (int e : values) { | |
if (e > 3 && e % 2 == 0) { | |
result = e * 2; | |
break; | |
} | |
} | |
System.out.println(total); | |
System.out.println( | |
values.stream() // Or, `parallelStream()`. | |
.filter(value -> value > 3) | |
.filter(Sample::isEven) | |
.map(value -> value * 2) | |
.findFirst() | |
.orElse(0) | |
); | |
} | |
public static boolean isEven(int number) { | |
return number % 2 == 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment