-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmatchString.java
29 lines (25 loc) · 923 Bytes
/
matchString.java
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.ArrayList;
import java.util.Arrays;
public class matchString{
static String[] guessIt(String message, String[] options) {
ArrayList<String> resultString = new ArrayList<>();
String[] finalString;
for (int i=0;i<options.length;i++){
//added comparison for all Letter Cases
if (options[i].toLowerCase().startsWith(message.toLowerCase())){
resultString.add(options[i]);
}
}
int len = resultString.size();
finalString = new String[len];
for (int y = 0;y<len;y++){
finalString[y] = resultString.get(y);
}
return finalString;
}
public static void main(String[] args) {
String[] res = guessIt("prizes",
new String[]{"abra", "pzies","prizesssssss", "prizes$", "prizes"});
System.out.println(Arrays.toString(res));
}
}