Comparing/ checking equality against multiple Strings.
Transcribed from the original LinkedIn image post.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| /*
Checking equality against multiple string
*/
import java.util.List;
import java.util.stream.*;
public class Day01 {
public static void main(String[] args) {
String fileType = "mpeg";
// have to assure that given fileType and comparing strings
// are all in same case (case-sensitiveness)
if (List.of("jpg", "png", "avi", "mpeg", "docx").contains(fileType)) {
System.out.println("Founded file with type " + fileType);
}
// another way of doing it
if (Stream.of("jpg", "png", "avi", "mpeg", "docx").anyMatch(fileType::equalsIgnoreCase)) {
System.out.println("Founded file with type " + fileType);
}
}
}
|
The original LinkedIn graphic is preserved below.
