import java.util.ArrayList;
import java.util.Collections;
class dd {
public int[] solution(int[] arr, int divisor) {
ArrayList<Integer> result = new ArrayList<Integer>();
int [] divisorResult = new int[arr.length];
for (int i = 0; i < arr.length; i++){
if (arr[i]%divisor == 0){
result.add(arr[i]);
} else {
continue;
}
}
Collections.sort(result); // ArrayList 정렬
if (result.isEmpty()){
result.add(-1);
}
// List를 int 배열로 변환하여 반환
int[] answer = new int[result.size()];
for (int i = 0; i < result.size(); i++) {
answer[i] = result.get(i);
}
return answer;
}
}
https://school.programmers.co.kr/learn/courses/30/lessons/12910