java 将字符串数组变为字典顺序排序后的字符串数组

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class StringUtil {

public static String[] stringSort(String [] s) {
List<String> list = new ArrayList<String>(s.length);
for (int i = 0; i < s.length; i++) {
list.add(s[i]);
}
Collections.sort(list);
return list.toArray(s);
}

public static void main(String[] args) {
String[] s = new String[]{"fuck", "suck", "apple", "jam"};
s = stringSort(s);
for (int i = 0; i < s.length; i++) {
System.out.println(s[i]);
}
}

}

 

posted @ 2015-12-14 16:54  Earic  阅读(6709)  评论(0编辑  收藏  举报