{"id":307,"date":"2023-02-01T09:34:00","date_gmt":"2023-02-01T09:34:00","guid":{"rendered":"http:\/\/ebhor.com\/?p=307"},"modified":"2023-02-01T15:39:52","modified_gmt":"2023-02-01T15:39:52","slug":"java-indexof-and-last-indexof","status":"publish","type":"post","link":"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/","title":{"rendered":"indexof and lastindexof Java Examples"},"content":{"rendered":"
public class StringIndexOf {\n\n    public static void main(String[] args) {\n        String sentence = \"This is a ball. its color is black\";\n        System.out.println(\"first index of \\\"l\\\" is \" + sentence.indexOf('l'));\n        System.out.println(\"first index of \\\"l\\\" after position 15 is \" + sentence.indexOf('l', 15));\n        int i = sentence.lastIndexOf('l');\n        System.out.println(\"last index of \\\"l\\\" is \" + i);\n        System.out.println(\"last index of \\\"l\\\" is \" + sentence.lastIndexOf('l',23));\n     }\n}\n<\/pre>\n

indexOf(int ch)<\/strong> returns int value that is the first occurrence of specified character in given string. Counting start from 0. If character not found it returns -1
\nindexOf(int ch, int fromIndex)<\/strong> returns int value that is the first occurrence of specified character in given string after specified position. If character not found it returns -1.
\nlastIndexOf(int ch)<\/strong>return int value that is last occurrence of specified character.
\npublic int lastIndexOf(int ch,int fromIndex)<\/strong> Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index<\/p>\n","protected":false},"excerpt":{"rendered":"

public class StringIndexOf { public static void main(String[] args) { String sentence = “This is a ball. its color is black”; System.out.println(“first index of \\”l\\” is ” + sentence.indexOf(‘l’)); System.out.println(“first index of \\”l\\” after position 15 is ” + sentence.indexOf(‘l’, 15)); int i = sentence.lastIndexOf(‘l’); System.out.println(“last index of \\”l\\” is ” + i); System.out.println(“last index … Read more<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[],"yoast_head":"\nindexof and lastindexof Java Examples - Ebhor.com<\/title>\n<meta name=\"description\" content=\"Java String use of indexOf and lastIndexOf with suitable example result and explanation with arguments and return type of methods\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"indexof and lastindexof Java Examples - Ebhor.com\" \/>\n<meta property=\"og:description\" content=\"Java String use of indexOf and lastIndexOf with suitable example result and explanation with arguments and return type of methods\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/\" \/>\n<meta property=\"og:site_name\" content=\"Ebhor.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ebhorcom\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-01T09:34:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-01T15:39:52+00:00\" \/>\n<meta name=\"author\" content=\"Manish Sahu\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Manish Sahu\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/\"},\"author\":{\"name\":\"Manish Sahu\",\"@id\":\"https:\/\/www.ebhor.com\/#\/schema\/person\/739b412ac50b5086f2e0f4aabc7a5b1a\"},\"headline\":\"indexof and lastindexof Java Examples\",\"datePublished\":\"2023-02-01T09:34:00+00:00\",\"dateModified\":\"2023-02-01T15:39:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/\"},\"wordCount\":102,\"publisher\":{\"@id\":\"https:\/\/www.ebhor.com\/#organization\"},\"articleSection\":[\"java\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/\",\"url\":\"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/\",\"name\":\"indexof and lastindexof Java Examples - Ebhor.com\",\"isPartOf\":{\"@id\":\"https:\/\/www.ebhor.com\/#website\"},\"datePublished\":\"2023-02-01T09:34:00+00:00\",\"dateModified\":\"2023-02-01T15:39:52+00:00\",\"description\":\"Java String use of indexOf and lastIndexOf with suitable example result and explanation with arguments and return type of methods\",\"breadcrumb\":{\"@id\":\"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.ebhor.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"indexof and lastindexof Java Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.ebhor.com\/#website\",\"url\":\"https:\/\/www.ebhor.com\/\",\"name\":\"Ebhor.com\",\"description\":\"Read The Latest Post Java, Css, Html, Php learning articles\",\"publisher\":{\"@id\":\"https:\/\/www.ebhor.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.ebhor.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.ebhor.com\/#organization\",\"name\":\"Ebhor.com\",\"url\":\"https:\/\/www.ebhor.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.ebhor.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.ebhor.com\/wp-content\/uploads\/2021\/05\/cropped-cropped-cropped-ebhor_logo_100x.jpg\",\"contentUrl\":\"https:\/\/www.ebhor.com\/wp-content\/uploads\/2021\/05\/cropped-cropped-cropped-ebhor_logo_100x.jpg\",\"width\":100,\"height\":100,\"caption\":\"Ebhor.com\"},\"image\":{\"@id\":\"https:\/\/www.ebhor.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/ebhorcom\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.ebhor.com\/#\/schema\/person\/739b412ac50b5086f2e0f4aabc7a5b1a\",\"name\":\"Manish Sahu\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.ebhor.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/edd13cce4f5daef0209636707c30eba3?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/edd13cce4f5daef0209636707c30eba3?s=96&r=g\",\"caption\":\"Manish Sahu\"},\"sameAs\":[\"http:\/\/ebhor.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"indexof and lastindexof Java Examples - Ebhor.com","description":"Java String use of indexOf and lastIndexOf with suitable example result and explanation with arguments and return type of methods","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:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/","og_locale":"en_US","og_type":"article","og_title":"indexof and lastindexof Java Examples - Ebhor.com","og_description":"Java String use of indexOf and lastIndexOf with suitable example result and explanation with arguments and return type of methods","og_url":"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/","og_site_name":"Ebhor.com","article_publisher":"https:\/\/www.facebook.com\/ebhorcom\/","article_published_time":"2023-02-01T09:34:00+00:00","article_modified_time":"2023-02-01T15:39:52+00:00","author":"Manish Sahu","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Manish Sahu","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/#article","isPartOf":{"@id":"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/"},"author":{"name":"Manish Sahu","@id":"https:\/\/www.ebhor.com\/#\/schema\/person\/739b412ac50b5086f2e0f4aabc7a5b1a"},"headline":"indexof and lastindexof Java Examples","datePublished":"2023-02-01T09:34:00+00:00","dateModified":"2023-02-01T15:39:52+00:00","mainEntityOfPage":{"@id":"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/"},"wordCount":102,"publisher":{"@id":"https:\/\/www.ebhor.com\/#organization"},"articleSection":["java"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/","url":"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/","name":"indexof and lastindexof Java Examples - Ebhor.com","isPartOf":{"@id":"https:\/\/www.ebhor.com\/#website"},"datePublished":"2023-02-01T09:34:00+00:00","dateModified":"2023-02-01T15:39:52+00:00","description":"Java String use of indexOf and lastIndexOf with suitable example result and explanation with arguments and return type of methods","breadcrumb":{"@id":"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.ebhor.com\/java-indexof-and-last-indexof\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.ebhor.com\/"},{"@type":"ListItem","position":2,"name":"indexof and lastindexof Java Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.ebhor.com\/#website","url":"https:\/\/www.ebhor.com\/","name":"Ebhor.com","description":"Read The Latest Post Java, Css, Html, Php learning articles","publisher":{"@id":"https:\/\/www.ebhor.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.ebhor.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.ebhor.com\/#organization","name":"Ebhor.com","url":"https:\/\/www.ebhor.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.ebhor.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.ebhor.com\/wp-content\/uploads\/2021\/05\/cropped-cropped-cropped-ebhor_logo_100x.jpg","contentUrl":"https:\/\/www.ebhor.com\/wp-content\/uploads\/2021\/05\/cropped-cropped-cropped-ebhor_logo_100x.jpg","width":100,"height":100,"caption":"Ebhor.com"},"image":{"@id":"https:\/\/www.ebhor.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ebhorcom\/"]},{"@type":"Person","@id":"https:\/\/www.ebhor.com\/#\/schema\/person\/739b412ac50b5086f2e0f4aabc7a5b1a","name":"Manish Sahu","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.ebhor.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/edd13cce4f5daef0209636707c30eba3?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/edd13cce4f5daef0209636707c30eba3?s=96&r=g","caption":"Manish Sahu"},"sameAs":["http:\/\/ebhor.com"]}]}},"_links":{"self":[{"href":"https:\/\/www.ebhor.com\/wp-json\/wp\/v2\/posts\/307"}],"collection":[{"href":"https:\/\/www.ebhor.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ebhor.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ebhor.com\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ebhor.com\/wp-json\/wp\/v2\/comments?post=307"}],"version-history":[{"count":1,"href":"https:\/\/www.ebhor.com\/wp-json\/wp\/v2\/posts\/307\/revisions"}],"predecessor-version":[{"id":14569,"href":"https:\/\/www.ebhor.com\/wp-json\/wp\/v2\/posts\/307\/revisions\/14569"}],"wp:attachment":[{"href":"https:\/\/www.ebhor.com\/wp-json\/wp\/v2\/media?parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ebhor.com\/wp-json\/wp\/v2\/categories?post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ebhor.com\/wp-json\/wp\/v2\/tags?post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}