forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrings.java
More file actions
32 lines (23 loc) · 879 Bytes
/
Strings.java
File metadata and controls
32 lines (23 loc) · 879 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
30
31
32
package modern.challenge;
import java.util.regex.Pattern;
public final class Strings {
private Strings() {
throw new AssertionError("Cannot be instantiated");
}
public static boolean containsV1(String text, String subtext) {
if (text == null || subtext == null
|| text.isBlank() || subtext.isBlank()) {
// or throw IllegalArgumentException
return false;
}
return text.matches("(?i).*" + Pattern.quote(subtext) + ".*");
}
public static boolean containsV2(String text, String subtext) {
if (text == null || subtext == null
|| text.isBlank() || subtext.isBlank()) {
// or throw IllegalArgumentException
return false;
}
return text.indexOf(subtext) != -1; // or lastIndexOf()
}
}