나는 String
인 객체 값을 가진 List<Bean>
을 가지고 있습니다. 이 문자열은 다음과 같습니다. "This is 1", "This is 10", "This is 2", "This is 11"
제 질문은 guava를 사용하여 1, 2, 10, 11? 나는 그것이 1, 10, 11, 2
당신이 좀 도와 주시겠습니까처럼 정렬하려면 같은 자바에서 문자열 정렬
List<Bean> orderedList = new ArrayList<>();
Function<Bean, String> getNameFunction = new Function<Bean, String>() {
@Override
public String apply(Bean from) {
return from.getShape();
}
};
Ordering<Bean> nameOrdering = Ordering.natural().onResultOf(getNameFunction);
ImmutableSortedSet<Bean> sortedShapes = ImmutableSortedSet.orderedBy(
nameOrdering).addAll(lb).build();
orderedList.addAll(sortedShapes);
return orderedList;
이
가 작동하지 않습니다?감사합니다.
. 이것은 일종의 예상대로 작동 할 수 있도록 표준화 된 방법입니다. – Kon
숫자 대신 문자열을 주문 하시겠습니까? – ra2085
주문 1, 10, 11, 2가 나에게 맞는 것 같습니다. 당신은 현악기를 주문하고 있습니다. – ra2085