I would at first parse numbers as integers, put them to the set and compare them:
import java.util.SortedSet;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class StringsCompare {
private static String one = "1 2 3 4 5 6";
private static String two = " 3 2 1 5 6 4 ";
public static void main(String[] args) {
StringsCompare sc = new StringsCompare();
System.out.println(sc.compare(one, two));
}
private boolean compare(String one, String two) {
SortedSet<Integer> setOne = getSet(one);
SortedSet<Integer> setTwo = getSet(two);
return setOne.equals(setTwo);
}
private SortedSet<Integer> getSet(String str) {
SortedSet<Integer> result = new TreeSet<Integer>();
StringTokenizer st = new StringTokenizer(str, " ");
while (st.hasMoreTokens()) {
result.add(Integer.valueOf(st.nextToken()));
}
return result;
}
}