-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyExercise3_9.java
29 lines (26 loc) · 992 Bytes
/
keyExercise3_9.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.Arrays;
public class keyExercise3_9 {
public static String[] filterEmails(String[] items){
// TODO: add your code here
String[] emails = new String[items.length];
int matchCount = 0;
for (int i = 0; i < items.length; i++) {
if (items[i].contains("@")) {
emails[matchCount] = items[i];
matchCount++;
}
}
String[] print = Arrays.copyOf(emails, matchCount);
return print;
}
public static void printItems(String[] items){
// TODO: add your code here
System.out.println(Arrays.toString(items));
}
public static void main(String[] args) {
printItems(filterEmails(new String[]{}));
printItems(filterEmails(new String[]{"abc"}));
printItems(filterEmails(new String[]{"[email protected]", "aab", "[email protected]", "some@"}));
printItems(filterEmails(new String[]{"xyz", "@bee.com", "aab"}));
}
}