我输入来自用户的字符串,然后列表进行排序,在第一个步骤,然后除去在第二个重复step.But的代码是给error.Please帮助! !为什么我的代码不转换的SortedSet到数组
下面是代码
import java.util.*;
class stringSort
{
public static void main(String args[])
{
String s1;
char[]s2;
System.out.println("Enter the string");
Scanner s=new Scanner(System.in);
s1=s.next();
//call the sort method to sort the string
s2=sort(s1);
System.out.println(String.valueOf(s2));
//remove duplicate entries in the sorted string
SortedSet<Character> set=new TreeSet<Character>();
set.addAll(Arrays.asList(s2));
System.out.println(String.valueOf(set.toArray()));
}
static char[] sort(String s)
{
char []temp=s.toCharArray();
Arrays.sort(temp);
return temp;
}
}
它给人的错误
no suitable method found for addAll(List<char[]>) set.addAll(Arrays.asList(s2));
随着1000+的声誉,你应该能够告诉什么是错误..张贴请。 – Maroun
你忘了告诉我们你得到了什么错误? – jpw
为什么不使用'set.toArray()'来代替?此外,'的SortedSet'。 –