I'm trying to remove the duplicates and sort the String array but I'm unable to do it. I'm not getting what I'm doing wrong. Please check the code.
String [] s = {"a", "y", "x","a","d", "y","m"};
Set st = new HashSet();
st.add(s);
Array.sort(st);
When I do this, I'm getting this error.
The method sort(int[]) in the type Arrays is not applicable for the arguments (Set).
As per my sense we should first remove duplicates by using the Set interface and then we have to sort them. But I'm unable to print even the st reference variable also([[Ljava.lang.String;@1d9dc39]) getting this error.
Please help me.
TreeSetis what you need .st.add(s);you are adding the array to the set. You have to add the elements of the array to the set. You can do this withset.addAll(Arrays.asList(s))or aforloop. These problems could be avoided if you used generics....