Skip to content

Instantly share code, notes, and snippets.

@danialgoodwin
Created January 29, 2015 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danialgoodwin/b05407bd9649d835d5f1 to your computer and use it in GitHub Desktop.
Save danialgoodwin/b05407bd9649d835d5f1 to your computer and use it in GitHub Desktop.
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