{"id":226,"date":"2016-05-06T21:06:00","date_gmt":"2016-05-06T21:06:00","guid":{"rendered":"http:\/\/www.java2blog.com\/?p=226"},"modified":"2023-11-25T10:01:16","modified_gmt":"2023-11-25T04:31:16","slug":"java-string-substring-example","status":"publish","type":"post","link":"https:\/\/java2blog.com\/java-string-substring-example\/","title":{"rendered":"Java String substring 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_substring_Example\">String substring Example:<\/a><\/li><\/ul><\/div>\n<div dir=\"ltr\" style=\"text-align: left;\">String&#8217;s substring method is used to fetch part of a String.It returns a new String which is substring of given String. substring is nothing but subset of given String.<\/p>\n<p>There are two overloaded methods for substring.<\/p>\n<h4 style=\"text-align: left;\"><span id=\"Method_Signature\">Method Signature:<\/span><\/h4>\n<pre name=\"code\">public String substring(int startIndex)<\/pre>\n<p>It returns a new String which is substring of given String from specified startIndex(Inclusive)<\/p>\n<pre name=\"code\">public String substring(int startIndex, int endIndex)<\/pre>\n<p>It returns a new String which is substring of given String from specified startIndex(Inclusive) to endIndex(Exclusive)<\/p>\n<blockquote><p>String&#8217;s index always starts with 0. In case of substring method, startIndex is always inclusive and endIndex is exclusive<\/p><\/blockquote>\n<h4><span id=\"String_substring_Example\">String substring Example:<\/span><\/h4>\n<pre name=\"code\">package org.arpit.java2blog;\n\npublic class StringSubStringExample {\n\n public static void main(String[] args) {\n\n  String str1= \"java2blog.com\";\n\n  \/\/ using beginIndex\n  System.out.println(str1.substring(5));\n  \/\/ using beginIndex and endIndex\n  System.out.println(str1.substring(5,9));\n }\n}\n\n<\/pre>\n<p>When you run above program, you will get below output:<\/p>\n<pre name=\"code\">blog.com\nblog<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Table of ContentsMethod Signature:String substring Example: String&#8217;s substring method is used to fetch part of a String.It returns a new String which is substring of given String. substring is nothing but subset of given String. There are two overloaded methods for substring. Method Signature: public String substring(int startIndex) It returns a new String which is [&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\/226"}],"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=226"}],"version-history":[{"count":1,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/226\/revisions"}],"predecessor-version":[{"id":25717,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/226\/revisions\/25717"}],"wp:attachment":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/media?parent=226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/categories?post=226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/tags?post=226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}