{"id":13604,"date":"2020-07-21T18:54:56","date_gmt":"2020-07-22T01:54:56","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=13604"},"modified":"2023-12-01T03:55:31","modified_gmt":"2023-12-01T11:55:31","slug":"java-compare-strings","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/java-compare-strings\/","title":{"rendered":"Java Compare Strings: A Step-By-Step Guide"},"content":{"rendered":"\n<p><em>There are three ways to compare strings in Java. The Java <code>equals()<\/code> method compares two string objects, the equality operator <code>==<\/code> compares two strings, and the <code>compareTo()<\/code> method returns the number difference between two strings. <\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>String comparison is a crucial part of working with strings in Java. For instance, if you\u2019re building an app for a coffee shop that checks who ordered which drink, you may want to compare the name of the customer with the one you have on-file.<\/p>\n\n\n\n<p>This tutorial will discuss, with reference and examples, how to compare strings in Java. We will discuss the three main options used to compare strings, and explore the limitations of the <code>==<\/code> operator when comparing strings in Java.<\/p>\n\n\n\n<p>By the end of reading this tutorial, you\u2019ll be an expert at comparing strings in Java.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Java Strings<\/h2>\n\n\n\n<p>Strings are used for storing text-based data in programming. Strings in Java are defined as a sequence of characters surrounded by double quotation marks. Here\u2019s an example of a string in Java:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>String day = &quot;Monday&quot;;<\/pre><\/div>\n\n\n\n<p>In this example, we declare a string called <code>day<\/code> which stores the value <code>Monday<\/code>.<\/p>\n\n\n\n<p>But what if we wanted to compare this string with another string? There are three main methods which can be used to compare strings in Java. These are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Using the <code>==<\/code> operator<\/li><li>Using the <code>equals()<\/code> and <code>equalsIgnoreCase()<\/code> methods<\/li><li>Using the <code>compareTo()<\/code> and <code>compareToIgnoreCase()<\/code> methods<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Compare Strings Using ==<\/h2>\n\n\n\n<p>The <code>==<\/code> operator, known as the equality operator, is used to compare two strings in Java.<\/p>\n\n\n\n<p>Suppose we are operating a coffee shop and we want to compare whether a customer\u2019s name matches the one we have associated with a particular order. We could compare these names using the following code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>public class CompareNames {\n\tpublic static void main(String[] args) {\n\t\tString orderName = &quot;James&quot;;\n\t\tString customerName = &quot;James&quot;;\n\n\t\tif (orderName == customerName) {\n\t\t\tSystem.out.println(&quot;The customer's name matches the order name.&quot;);\n\t\t} else {\n\t\t\tSystem.out.println(&quot;The customer's name does not match the order name.&quot;);\n\t\t}\n\t}\n}<\/pre><\/div>\n\n\n\n<p>Our code returns: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>The customer's name matches the order name.<\/pre><\/div>\n\n\n\n<p>Let\u2019s break down our code. First, we declare a class called <code>CompareNames<\/code> which stores the code for our program. We then declare a variable called <code>orderName<\/code> which stores the name associated with a particular order, and a variable called <code>customerName<\/code> which stores the name of the customer who is looking for their drink.<\/p>\n\n\n\n<p>We then use an if statement and the equality operator to compare the value of <code>orderName<\/code> and the value of <code>customerName<\/code>. Here\u2019s the line of code which performs this comparison:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>if (orderName == customerName)<\/pre><\/div>\n\n\n\n<p>If the values stored within <code>orderName<\/code> and <code>customerName<\/code> are equal\u2014which they are in this case\u2014the message <code>The customer\u2019s name matches the order name.<\/code> is printed to the console. Otherwise, the message <code>The customer\u2019s name does not match the order name.<\/code> is printed to the console.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Compare String Objects Using ==<\/h2>\n\n\n\n<p>In the above example, we declared two strings and used the <code>==<\/code> operator to compare them. However, this approach does not work when you are comparing two string objects.<\/p>\n\n\n\n<p>Here\u2019s what happens if we try to compare two string objects using the <code>==<\/code> operator:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>public class CompareNames {\n\tpublic static void main(String[] args) {\n\t\tString orderName = new String(&quot;James&quot;);\n\t\tString customerName = new String(&quot;James&quot;);\n\n\t\tif (orderName == customerName) {\n\t\t\tSystem.out.println(&quot;The customer's name matches the order name.&quot;);\n\t\t} else {\n\t\t\tSystem.out.println(&quot;The customer's name does not match the order name.&quot;);\n\t\t}\n\t}\n}<\/pre><\/div>\n\n\n\n<p>Our code returns: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>The customer's name does not match the order name.<\/pre><\/div>\n\n\n\n<p>Even though we assign the string value <code>James<\/code> to both string objects, the program does not treat them the same. This is because the program will not compare the value of the strings, rather the objects themselves.<\/p>\n\n\n\n<p>In our code, we have declared two string objects, each of which have different object references. So, when we try to compare them using <code>==<\/code>, our program treats them as different objects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Compare Strings Using equals()<\/h2>\n\n\n\n<p>The Java string <code>equals()<\/code> method compares two strings in Java.<\/p>\n\n\n\n<p>Let\u2019s return to the coffee shop example. Suppose we want to compare the name we have associated with a coffee order and the name of a customer. We could do so using this code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>public class CompareNames {\n\tpublic static void main(String[] ags) {\n\t\tString orderName = &quot;James&quot;;\n\t\tString customerName = &quot;James&quot;;\n\n\t\tbool areEqual = orderName.equals(customerName);\n\t\t\nif (areEqual) {\n\t\t\tSystem.out.println(&quot;The customer's name matches the order name.&quot;);\n\t\t} else {\n\t\t\tSystem.out.println(&quot;The customer's name does not match the order name.&quot;);\n\t\t}\n\t}\n}<\/pre><\/div>\n\n\n\n<p>Our code returns: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>The customer's name matches the order name.<\/pre><\/div>\n\n\n\n<p>In this example we use the <code>equals()<\/code> method to compare the values of <code>orderName<\/code> and <code>customerName<\/code>.<\/p>\n\n\n\n<p>We then assign the value of the <code>equals()<\/code> method to a boolean called <code>areEqual<\/code>. If <code>areEqual<\/code> returns true, a message stating <code>The customer\u2019s name matches the order name.<\/code> is printed to the console; otherwise, if <code>areEqual<\/code> returns false, a message stating <code>The customer\u2019s name does not match the order name.<\/code> is printed to the console. In this case, <code>orderName<\/code> and <code>customerName<\/code> is equal, so <code>areEqual<\/code> is equal to true.<\/p>\n\n\n\n<p>You can use the <code>equalsIgnoreCase()<\/code> method in the same way as <code>equals()<\/code> to compare strings. The only difference between <code>equals()<\/code> and <code>equalsIgnoreCase()<\/code> is that the latter compares two strings irrespective of their case, whereas the former is case sensitive.<\/p>\n\n\n\n<p>If you\u2019re interested in learning more about the string <code>equals()<\/code> method, read our tutorial on the topic.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Compare Strings Using compareTo()<\/h2>\n\n\n\n<p>The Java string <code>compareTo()<\/code> method is used to compare two strings lexicographically.<\/p>\n\n\n\n<p>The <code>compareTo()<\/code> method compares the Unicode value of each character in the two strings you are comparing. <code>compareTo()<\/code> returns 0 if the string is equal to the other string, less than 0 if the string has fewer characters than the other string, and greater than 0 if the string has more characters than the other string.&nbsp;<\/p>\n\n\n\n<p>Suppose we wanted to compare the names of our coffee shop customer and the name we have associated with a drink lexicographically. We could do so using this code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>public class CompareNames {\n\tpublic static void main(String[] ags) {\n\t\tString orderName = &quot;James&quot;;\n\t\tString customerName = &quot;Bill&quot;;\n\n\t\tint difference = orderName.compareTo(customerName);\n\t\t\n\t\tSystem.out.println(&quot;Difference: &quot; + difference);\n\t}\n}<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Difference: 8<\/pre><\/div>\n\n\n\n<p>In this example, our code uses <code>compareTo()<\/code> to compare the value of <code>customerName<\/code> to the value of <code>orderName<\/code>. In this case, the value of <code>orderName<\/code>, <code>James<\/code>, does not match the value of <code>customerName<\/code>, <code>Bill<\/code>.<\/p>\n\n\n\n<p>Because <code>orderName<\/code> has more characters than <code>customerName<\/code>, our code returns a value greater than 0, equal to the Unicode differences in our two strings.<\/p>\n\n\n\n<p>In addition, the <code>compareTo()<\/code> method is case sensitive. If you want to compare strings lexicographically without regard for the cases of the characters in your strings, you can use the <code>compareToIgnoreCase()<\/code> method. The syntax for the <code>compareTo()<\/code> and <code>compareToIgnoreCase()<\/code> method is the same.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Comparing the values stored in two strings is a common operation in Java.<\/p>\n\n\n\n<p>This tutorial discussed how to compare two strings using the equality operator (<code>==<\/code>), the <code>equals()<\/code> method, and the <code>compareTo()<\/code> method. We also discussed the limitations of the equality operator in comparing objects. We also walked through an example of each of these methods in action.<\/p>\n\n\n\n<p>You now have the skills you need to start comparing strings in Java like a professional coder!<\/p>\n","protected":false},"excerpt":{"rendered":"There are three ways to compare strings in Java. The Java equals() method compares two string objects, the equality operator == compares two strings, and the compareTo() method returns the number difference between two strings. String comparison is a crucial part of working with strings in Java. For instance, if you\u2019re building an app for&hellip;","protected":false},"author":240,"featured_media":13605,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17289],"tags":[],"class_list":{"0":"post-13604","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-java"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Java","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Java Compare Strings: A Step-By-Step Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"The equality operator, equals() method, and compareTo() method compare Java strings. On Career Karma, learn how to compare strings.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/java-compare-strings\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Compare Strings: A Step-By-Step Guide\" \/>\n<meta property=\"og:description\" content=\"The equality operator, equals() method, and compareTo() method compare Java strings. On Career Karma, learn how to compare strings.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/java-compare-strings\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-22T01:54:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:55:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/people-sitting-while-discussing-3182827.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"681\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-compare-strings\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-compare-strings\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Java Compare Strings: A Step-By-Step Guide\",\"datePublished\":\"2020-07-22T01:54:56+00:00\",\"dateModified\":\"2023-12-01T11:55:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-compare-strings\\\/\"},\"wordCount\":928,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-compare-strings\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/people-sitting-while-discussing-3182827.jpg\",\"articleSection\":[\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-compare-strings\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-compare-strings\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-compare-strings\\\/\",\"name\":\"Java Compare Strings: A Step-By-Step Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-compare-strings\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-compare-strings\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/people-sitting-while-discussing-3182827.jpg\",\"datePublished\":\"2020-07-22T01:54:56+00:00\",\"dateModified\":\"2023-12-01T11:55:31+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"The equality operator, equals() method, and compareTo() method compare Java strings. On Career Karma, learn how to compare strings.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-compare-strings\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-compare-strings\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-compare-strings\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/people-sitting-while-discussing-3182827.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/people-sitting-while-discussing-3182827.jpg\",\"width\":1020,\"height\":681},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-compare-strings\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Java Compare Strings: A Step-By-Step Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Java Compare Strings: A Step-By-Step Guide | Career Karma","description":"The equality operator, equals() method, and compareTo() method compare Java strings. On Career Karma, learn how to compare strings.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/java-compare-strings\/","og_locale":"en_US","og_type":"article","og_title":"Java Compare Strings: A Step-By-Step Guide","og_description":"The equality operator, equals() method, and compareTo() method compare Java strings. On Career Karma, learn how to compare strings.","og_url":"https:\/\/careerkarma.com\/blog\/java-compare-strings\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-07-22T01:54:56+00:00","article_modified_time":"2023-12-01T11:55:31+00:00","og_image":[{"width":1020,"height":681,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/people-sitting-while-discussing-3182827.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/java-compare-strings\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/java-compare-strings\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Java Compare Strings: A Step-By-Step Guide","datePublished":"2020-07-22T01:54:56+00:00","dateModified":"2023-12-01T11:55:31+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/java-compare-strings\/"},"wordCount":928,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/java-compare-strings\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/people-sitting-while-discussing-3182827.jpg","articleSection":["Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/java-compare-strings\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/java-compare-strings\/","url":"https:\/\/careerkarma.com\/blog\/java-compare-strings\/","name":"Java Compare Strings: A Step-By-Step Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/java-compare-strings\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/java-compare-strings\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/people-sitting-while-discussing-3182827.jpg","datePublished":"2020-07-22T01:54:56+00:00","dateModified":"2023-12-01T11:55:31+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"The equality operator, equals() method, and compareTo() method compare Java strings. On Career Karma, learn how to compare strings.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/java-compare-strings\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/java-compare-strings\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/java-compare-strings\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/people-sitting-while-discussing-3182827.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/people-sitting-while-discussing-3182827.jpg","width":1020,"height":681},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/java-compare-strings\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/careerkarma.com\/blog\/java\/"},{"@type":"ListItem","position":3,"name":"Java Compare Strings: A Step-By-Step Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/13604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=13604"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/13604\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/13605"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=13604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=13604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=13604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}