-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSteamMax.java
More file actions
29 lines (19 loc) · 798 Bytes
/
SteamMax.java
File metadata and controls
29 lines (19 loc) · 798 Bytes
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
import java.util.*;
import java.util.Optional;
import java.util.Comparator;
class SteamMax {
public static void main(String[] args)
{
// list of integers
List<Integer> listNum = Arrays.asList(-7, 30, 44, 23, 19);
// array of strings
List<String> listStr = Arrays.asList("hack", "hacktoberfest2021", "digitalocean",
"appwrite");
Integer maxNum = listNum.stream().max(Integer::compare).get();
OptionalInt maxStr = listStr.stream().mapToInt(String::length).max();
System.out.println("The maximum Number is : "+maxNum);
if (maxStr.isPresent()) {
System.out.println("The maximum length of Strings is : "+maxStr.getAsInt());
}
}
}