2
SimpleSortingVector를 사용하여 Blackberry 앱의 Vector를 정렬하는 데 문제가 있습니다. 내 물건은별로 변하지 않아. 여기SimpleSortingVector를 사용하여 블랙 베리에서 벡터를 정렬하는 방법은 무엇입니까?
는
private Vector vector = new Vector(); //Assume that this vector is populated with elements already
SimpleSortingVector ssv = new SimpleSortingVector();
ssv.setSortComparator(new Comparator() {
public int compare(Object o1, Object o2) {
Record o1C = (Record)o1;
Record o2C = (Record)o2;
return o1C.getName().compareTo(o2C.getName());
}
public boolean equals(Object obj) {
return compare(this, obj) == 0;
}
});
for(int i=0;i<vector.size();i++){
Record record = new Record();
record=(Record) vector.elementAt(i);
//when you add elements to this vector, it is to post to be automatically sorted
ssv.addElement(record);
}
클래스 레코드
public class Record {
String name;
int price;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}
+1, 네가 옳다. 절망적 인 시도로서의 나의 대답. – dreamcrash
작동합니다. 고맙습니다. 비교가 빠르고로드가 적은 SimpleSortingVector.setSort (true) 또는 SimpleSortingVector.reSort()? – ejobity
나는 소스 코드를 볼 수 없으므로 나는 단지 교육 된 추측을 할 수있다. 둘 다 같은 점심 시간을 가져야합니다 : O (n log n). reSort()는 약간 작은 상수 요소로 정렬 할 수 있어야하므로 조금 더 빨라질 것입니다. –