假设字符串类似这样的aba和aab就相等,现在随便给你二组字符串,请编程比较他们看是否相等  
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));      
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}       
StringTokenizer st = new StringTokenizer(s);
String s1 = st.nextToken();
String s2 = st.nextToken();       
byte[] sa1 = s1.getBytes();
byte[] sb2 = s2.getBytes();
Arrays.sort(sa1);
Arrays.sort(sb2);       
String ss1 = new String(sa1);
String ss2 = new String(sb2);       
if(ss1.equals(ss2))
System.out.println("equal");
else
System.out.println("not equal");

解决方案 »

  1.   

    aba和aab当然不相等。
    但是你这里排序了
    Arrays.sort(sa1);
    Arrays.sort(sb2); 所以两个字符串都变成 aab了。这当然就相等了。如果是比较大小,就不要排序。这样就够了。public static void main(String[] args) {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s = null;
    try {
    s = br.readLine();
    } catch (IOException e) {
    e.printStackTrace();
    }
    StringTokenizer st = new StringTokenizer(s);
    String s1 = st.nextToken();
    String s2 = st.nextToken();
    if (s1.equals(s2))
    System.out.println("equal");
    else
    System.out.println("not equal");
    }
      

  2.   

    1楼是没有理解楼主的意思吧。楼主是说假设类似于aba和aab就相等