본문 바로가기
JAVA

[JAVA(자바)] The method sort(int[]) in the type Arrays is not applicable for the arguments 에러 해결 방법

by 초이사 2022. 12. 27.

The method sort(double[]) in the type Arrays is not applicable for the arguments (double[], Collections.reverseOrder())

 

배열이나 리스트를 내림차순으로 정렬할 때, Collections.reverseOrder()를 사용하면서 위와 같은 에러를 자주 볼 수 있다.

 

그 이유는  Collections는 객체에서만 사용가능하기 때문에 Primary type(기본 타입)인 int타입은 사용할 수 없다.

double, char등도 마찬가지이다. 기본타입을 Wrapper 클래스로 바꿔주어야 한다.

 

byte -> Byte

short -> Short

int -> Integer

long -> Long

float -> Float

double -> Double

char -> Character

boolean -> Boolean

 

위의 경우 Integer로 변경하면 에러가 뜨지 않는다.

 

댓글