import java.util.*;
public class Test {
public static void main(String[] args) {
String[] str = {"a","b","a","b","c","a","b","c","d"};
Set<String> set = new TreeSet<String>();
for(int i = 0;i < str.length;i++){
set.add(str[i]);
}
System.out.println(set); /*这里可以打印*/
String[] str1 = (String[])set.toArray();
for(String str2 : str1){
System.out.println(str2); /*
这里报错:Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; can
not be cast to [Ljava.lang.String;
*/
}
}
}
就是想用Set集合去重复,然后再转化成数组,但是报错了,大神帮我看下,谢谢
|