2011. 12. 1. 17:50 JAVA

방법1
Arrays.sort(UrlData.URLSName, new Comparator<Object>() {
 
public int compare(Object o1, Object o2) {
 
String t1 = (String) o1;

String t2 = (String) o2;

int re = t1.compareTo(t2);
 
return re;

}

});


방법2
ArrayList<String> alurlname = new ArrayList<String>();

Collections.sort(alurlname);//정렬

Collections.reverse(alurlname);//반대로 정렬

 
방법3

static void bubbleSort(String[] p_array) throws Exception {

boolean anyCellSorted;

int length = p_array.length;

String tmp;

for (int i = length; --i >= 0;) {

anyCellSorted = false;

for (int j = 0; j < i; j++) {

if (p_array[j].compareTo(p_array[j + 1]) > 0) {

tmp = p_array[j];

p_array[j] = p_array[j + 1];

p_array[j + 1] = tmp;

anyCellSorted = true;

}

}

if (anyCellSorted == false) {

return;

}

}





for문 돌려서 순서대로 비교할 일은 없을꺼 같네  

posted by 욱이다