{"id":210,"date":"2016-05-14T19:42:00","date_gmt":"2016-05-14T19:42:00","guid":{"rendered":"http:\/\/www.java2blog.com\/?p=210"},"modified":"2023-11-25T08:51:04","modified_gmt":"2023-11-25T03:21:04","slug":"java-string-equals-example","status":"publish","type":"post","link":"https:\/\/java2blog.com\/java-string-equals-example\/","title":{"rendered":"Java String equals example"},"content":{"rendered":"<div id=\"toc_container\" class=\"toc_light_blue no_bullets\"><p class=\"toc_title\">Table of Contents<\/p><ul class=\"toc_list\"><li><a href=\"#Method_Signature\">Method Signature:<\/a><\/li><li><a href=\"#String_equals_Example\">String equals Example:<\/a><\/li><\/ul><\/div>\n<div dir=\"ltr\" style=\"text-align: left;\">String&#8217;s equals method compares String with specified object. It checks if both have same character sequence. It is generally used to compare two Strings.<\/p>\n<h4 style=\"text-align: left;\"><span id=\"Method_Signature\">Method Signature:<\/span><\/h4>\n<pre name=\"code\">public boolean equals(Object anObject)<\/pre>\n<h4><span id=\"String_equals_Example\">String equals Example:<\/span><\/h4>\n<pre name=\"code\">package org.arpit.java2blog;\n\npublic class StringEqualsExamplesMain {\n public static void main(String[] args) {\n  String str1 = \"Hello world from java2blog.com\";\n  String str2 = new String(\"Hello world from java2blog.com\");\n  String str3 = \"Hello world from JAVA2BLOG.COM\";\n\n  if (str1.equals(str2)) {\n   System.out.println(\"1st and 2nd Strings are equal\");\n  } \n  else {\n   System.out.println(\"1st and 2nd Strings are not equal\");\n  }\n\n  if (str1.equals(str3)) {\n   System.out.println(\"1st and 3rd Strings are equal\");\n  } \n  else {\n   System.out.println(\"1st and 3rd Strings are not equal\");\n  }\n }\n}\n\n<\/pre>\n<p>When you run above program, you will get below output:<\/p>\n<pre name=\"code\">1st and 2nd Strings are equal\n1st and 3rd Strings are not equal<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Table of ContentsMethod Signature:String equals Example: String&#8217;s equals method compares String with specified object. It checks if both have same character sequence. It is generally used to compare two Strings. Method Signature: public boolean equals(Object anObject) String equals Example: package org.arpit.java2blog; public class StringEqualsExamplesMain { public static void main(String[] args) { String str1 = &#8220;Hello [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_mi_skip_tracking":false},"categories":[27],"tags":[],"_links":{"self":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/210"}],"collection":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":1,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/210\/revisions"}],"predecessor-version":[{"id":25674,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/210\/revisions\/25674"}],"wp:attachment":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/media?parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/categories?post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/tags?post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}