-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOddEvenNumberCheckInListExample.java
More file actions
43 lines (33 loc) · 1.39 KB
/
OddEvenNumberCheckInListExample.java
File metadata and controls
43 lines (33 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.codinginterview;
import java.util.ArrayList;
import java.util.List;
public class OddEvenNumberCheckInListExample {
public static void main(String[] args) {
System.out.println("Odd Even Number Check in a List Example");
List<Integer> numberList = List.of(2,4,6,78,34,22);
// numberList.add(30);
System.out.println("===== Using parallelStream function");
System.out.println(" ODD Number available ::"
+ numberList.parallelStream().anyMatch(x -> x % 2 != 0));
System.out.println(" Even Number available ::"
+ numberList.parallelStream().anyMatch(x -> x % 2 == 0));
System.out.println("===== Using stream function");
// only Stream
System.out.println(" ODD Number available ::"
+ numberList.stream().anyMatch(x -> x % 2 != 0));
System.out.println(" Even Number available ::"
+ numberList.stream().anyMatch(x -> x % 2 == 0));
System.out.println("===== Old Style");
// Old Style
for(int i : numberList){
if(i % 2 == 0){
System.out.println("Event number available!");
break;
}else if(i % 2 != 0){
System.out.println("Odd Number available!");
}else{
System.out.println("Something is wrong with the input!");
}
}
}
}