[Java] 纯文本查看 复制代码
import java.util.Arrays;
import java.util.Random;
public class Test1 {
public static void main(String[] args) {
//新建一个char类型数组
char[] charArray1=new char[26];
//利用循环往数组内添加元素
for (int i = 0; i < charArray1.length; i++) {
charArray1=(char)('a'+i);
}
//定义一个数组
String[] stringArray=new String[5];
Random rd=new Random();
for (int i = 0; i < stringArray.length; i++) {
String s="";
for (int i1 = 0; i1 < 3; i1++) {
int index=rd.nextInt(charArray1.length);
s+=charArray1[index];
}
stringArray=s;
}
System.out.println("排序前:");
System.out.println(Arrays.toString(stringArray));
Arrays.sort(stringArray);
System.out.println("排序后:");
System.out.println(Arrays.toString(stringArray));
}
}