내 답안
import java.util.*;
class Solution {
public List solution(String[] strArr) {
List<String> answer = new ArrayList<>();
for(int i = 0; i < strArr.length; i++){
if(!strArr[i].contains("ad")){
answer.add(strArr[i]);
}
}
return answer;
}
}
Java
복사
다른사람 풀이
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
class Solution {
public String[] solution(String[] strArr) {
List<String> list = Arrays.stream(strArr).filter(m -> !m.contains("ad")).collect(Collectors.toList());
String[] answer = new String[list.size()];
list.toArray(answer);
return answer;
}
}
Java
복사
import java.util.*;
class Solution {
public String[] solution(String[] strArr) {
ArrayList<String> al = new ArrayList<>();
for (String s : strArr) {
if (!s.contains("ad")) {
al.add(s);
}
}
return al.toArray(String[]::new);
}
}
Java
복사