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-10-10 11:30:33