- int[] a 역순정렬 Arrays.stream(a).boxed().sorted(Comparator.reverseOrder()).mapToInt(Integer::intValue).toArray();
- String[] a를 int[]배열로 Arrays.stream(a).mapToInt(Integer::parseInt).toArray();
- 객체 정렬
public class People implements Comparable<People>{
String name;
int age;
People(String name, int age){
this.name = name;
this.age = age;
}
@Override
public int compareTo(People people){
if(this.age > people.age){
return 1;
}else if(this.age == people.age){
return 0;
}else{
return -1;
}
}
}
'코딩테스트 > Algorithm' 카테고리의 다른 글
[알고리즘] 힙 정렬(heap sort) (0) | 2023.05.22 |
---|---|
[알고리즘] 병합 정렬(merge sort) (0) | 2023.05.22 |
[알고리즘] 퀵 정렬(quick sort) (2) | 2023.05.19 |