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]); } } }
时间: 2024-12-11 15:48:19