Suppose you have a string of the name of the person with the salutation of Mr or Ms and you want to use only the name of that person which means you have to remove the salutation from that string. So, you can say that a substring is a continuous subset of the string.
If you take “Sler” as a string then it is not a substring of the above string as it is not continuous in the given string. Now, here in the above string “Interviewbit” is a substring of the above string as it is a continuous sequence of characters in the given string. So substring is a contiguous sequence of characters in a string or you can say that substring is a part of a string and that part can be the whole string as well. We will start this article by substring definition. The first method returns a substring that starts from the specified index and goes to the end of the string, while the second method returns a substring that starts from the specified start index and ends at the specified end index (exclusive). There are two methods in Java to a substring of a specified string: A substring can consist of any number of characters, from a single character to the entire string itself.
For example, in the string 'Hello World'Īre all substrings. A substring is a contiguous sequence of characters within a string.