PackageCeshi.com.job;Importjava.util.ArrayList;Importjava.util.Arrays;Importjava.util.List; Public classEqualtest {/** * @paramargs*/ Public Static voidMain (string[] args) {//TODO auto-generated Method StubString A = "ABba"; String B= "Abbaa"; if(A.equals (B)) {System.out.println (Equal); }ElseSystem.out.println ("Not Equal"); System.out.println ("-------------");//string C = new String ("Hello");String C = "Hello"; String D= "Hello"; if(c==D) {System.out.println (Equal); }ElseSystem.out.println ("Not Equal"); System.out.println ("——————————————————————"); String[] E= {"1", "2", "3", "4"}; String[] F= {"1", "2", "3", "4"}; if(Arrays.equals (e,f)) {System.out.println (Equal); }ElseSystem.out.println ("Not Equal"); System.out.println ("---------ooo"); String[] G= {"1", "2", "3", "4"}; String[] H= {"1", "2", "3", "4"}; if(g.length==h.length) { for(inti = 0; i < g.length; i++) { if(G[i].equals (H[i])) {//System.out.println ("equal");}ElseSystem.out.println ("Not Equal"); } System.out.println (Equal); }Else{System.out.println ("Long, not equal, no need to judge."); } System.out.println ("-------------"); List<String> one = arrays.aslist ("Tom", "Anthony", "Beijing"); List<String> = Arrays.aslist ("Tom", "Anthony", "Beijing"); if(One.containsall ()) {System.out.println (Equal); }Else{System.out.println ("Not Equal"); } System.out.println ("-----------"); List<String> str1 = arrays.aslist ("Tom", "Anthony"); List<String> str2 = arrays.aslist ("Tom"); if(str1.size () = =str2.size ()) { for(inti = 0; I < str1.size (); i++) { if(Str1.get (i). Equals (Str2.get (i))) {//Do thing}Else{System.out.println ("Not the same"); }} System.out.println (""); }Else{System.out.println ("The length is not equal, there is no need to compare"); } } }
Determine if two objects are equal in Java