# Main.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<String> al = new ArrayList<>();
al.add("ab");
al.add("c");
Collections.sort(al, new Comparator<String>() {
// sorted by string length
@Override
public int compare(String o1, String o2) {
if (o1.length() == o2.length()) {
return 0;
}
return o1.length() > o2.length() ? -1 : 1;
}
});
for (String a : al) {
System.out.println(a);
}
}
}
# 결과
ab
c
댓글 영역