Skip to content

Instantly share code, notes, and snippets.

@hydai
Last active December 28, 2015 05:09
Show Gist options
  • Save hydai/7448038 to your computer and use it in GitHub Desktop.
Save hydai/7448038 to your computer and use it in GitHub Desktop.
class XIII {
public static void main (String[] args) {
StringBuffer s1, s2, s3;
s1 = new StringBuffer("Hello");
s2 = s1;
s1.append(" the Java master!");
s3 = new StringBuffer("Hello the Java master!");
// 比較法一
System.out.println(s1.toString().compareTo(s2.toString()) == 0);
System.out.println(s1.toString().compareTo(s3.toString()) == 0);
System.out.println(s2.toString().compareTo(s3.toString()) == 0);
// 比較法二
System.out.println(s1.toString().equals(s2.toString()));
System.out.println(s1.toString().equals(s3.toString()));
System.out.println(s2.toString().equals(s3.toString()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment