-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathJavaKey.java
More file actions
54 lines (44 loc) · 1.63 KB
/
Copy pathJavaKey.java
File metadata and controls
54 lines (44 loc) · 1.63 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
44
45
46
47
48
49
50
51
52
53
54
package com.ironhack.javaKeywords;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class JavaKey {
private String stringKey;
private final List<String> JAVA_KEYWORDS = Arrays.asList(
"abstract", "assert", "boolean", "break", "byte",
"case", "catch", "char", "class", "const",
"continue", "default", "do", "double", "else",
"enum", "extends", "final", "finally", "float",
"for", "goto", "if", "implements", "import",
"instanceof", "int", "interface", "long", "native",
"new", "package", "private", "protected", "public",
"return", "short", "static", "strictfp", "super",
"switch", "synchronized", "this", "throw", "throws",
"transient", "try", "void", "volatile", "while",
"true", "false", "null");
public JavaKey(String stringKey) {
this.stringKey = stringKey;
}
public String getStringKey() {
return stringKey;
}
public List<String> getJAVA_KEYWORDS() {
return JAVA_KEYWORDS;
}
public String compareKeyString() {
String[] words = this.stringKey.split("\\s+");
List<String> foundKeyWords = new ArrayList<>();
for (String word : words) {
for (String keyword : JAVA_KEYWORDS) {
if (word.equalsIgnoreCase((keyword))) {
foundKeyWords.add(word);
}
}
}
if (foundKeyWords.isEmpty()) {
return "Doesn't found any key word.";
} else {
return "Key word found: " + foundKeyWords;
}
}
}