I haven't used Java for a long time. Today, a new Java student asked me not to use the EQUAL () function to help him determine whether the strings are equal, let's review Java.
Package bzu.edu.cn; </P> <p> public class text {</P> <p>/** <br/> * @ Param ARGs <br/> */<br/> Public static void main (string [] ARGs) {<br/> // todo auto-generated method stub <br/> string str1 = "ABCD"; <br/> string str2 = "ABCD "; <br/> string str3 = "BaCe"; </P> <p> // determines whether the string is equal. <br/> If (equ (str1, str3 )) <br/>{< br/> system. out. println (str1 + "and" + str3 + "equal"); <br/>}else <br/>{< br/> system. out. println (str1 + "and" + Str3 + "not equal"); <br/>}</P> <p> If (equ (str1, str2 )) <br/>{< br/> system. out. println (str1 + "and" + str2 + "equal"); <br/>}else <br/>{< br/> system. out. println (str1 + "and" + str2 + "not equal "); <br/>}</P> <p> Public static Boolean equ (string str1, string str2) <br/>{< br/> Boolean isequ = false; // The initial values are not equal. <br/> If (str1.length () = str2.length ()) <br/>{< br/> for (INT I = 0; I <str1.length (); ++ I) <br/>{< br/> If (str1.char At (I )! = Str2.charat (I) <br/> return isequ; <br/>}< br/>} else <br/>{< br/> return isequ; <br/>}< br/> isequ = true; </P> <p> return isequ; <br/>}</P> <p >}< br/>