只有影子
2015-11-12 21:30
package collection_map_demon;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
public class String_test {
public List<String> StringList;
private Scanner console;
public String_test()
{
StringList = new ArrayList<String>();
}
public void setTest()
{
Random random = new Random();
StringBuffer[] slist = new StringBuffer[10];
for(int j=0;j<10;j++)
{
int i = random.nextInt(10)+1;
slist[j] = new StringBuffer(i);
String base = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
String s;
do
{
for(int k=0;k<i;k++)
{
int number = random.nextInt(base.length());
//slist[j].setCharAt(k,base.charAt(number));
slist[j].append(base.charAt(number));
}
s = slist[j].toString();
}while(StringList.contains(s));
StringList.add(s);
}
System.out.println("--------------------排序前-------------------------");
for(String s :StringList)
{
System.out.println(s);
}
System.out.println("--------------------排序后--------------------------");
Collections.sort(StringList);
for(String s : StringList)
{
System.out.println(s);
}
}
public static void main(String[] args) {
String_test t = new String_test();
t.setTest();
}
}
不会,String类中的equals方法已经重写了Object类中的equals方法,比较的是字符串的内容
Java入门第三季
409792 学习 · 4340 问题
相似问题