Determine if two objects are equal in Java

Source: Internet
Author: User

 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.