1. String comparison
Java
Comparing a String object cannot simply use the comparison operator "= =" because the comparison operator compares the address of a two string . Even though the contents of the two strings are the same, the memory addresses of the two objects are different, using the comparison operator is still
will return false. You need to use equals or equalsignorecase.
Examples are as follows:
Public Static voidMain (string[] args) {/** Comparisons of String objects cannot be done simply by using the comparison operator "= =" because the * comparison operator compares the addresses of two strings. Even if the contents of the two strings are the same, and the memory addresses of the two objects are different, the use of the comparison operator will still return false. * Need to use equals or equalsignorecase*/String S1=NewString ("ABC"); String S2=NewString ("ABC"); Booleanb =s1.equals (S2); BooleanB2 =s1.equalsignorecase (S2); System.out.println ("Equal result:" +b); System.out.println ("Equalsignorecase Result:" +b2);}
The results of the operation are as follows:
C#
In C #, for reference types, the equals sign (= =) compares the "references" of two variables, that is, whether the referenced "address" is the same. For equals, the "content" of the variable is still the same, since string is a string class in the Microsoft package, internally he has overridden the = = operator. after rewriting, he compares the contents of the two variables.
Examples are as follows:
Public Static void TestMethod () { string"ABC"; string " ABC " ; bool result = S1 = = S2; Console.WriteLine (result);}
2. String formatting
Java and C # are mainly formatted keywords, different forms, more details, not detailed introduction.
Java (C #) underlying differences-string