The syntax of substring() function is substring(int start, int end) StringBuilder.substring() returns a new String that contains a subsequence of characters currently contained in this sequence, whose starting and ending are provided as arguments. Output Exception: : start -7, end 13, length 13 substring(int start, int end) StringBuilder str = new StringBuilder("abcdefghijklm") We will give an index that is out of range for the sequence in StringBuilder. In this example, we will test a negative scenario where substring() throws. Sub String : fghijkl Example 2 – substring(int start) ("Sub String : "+ stringBuilder.substring(5)) StringBuilder stringBuilder = new StringBuilder("abcdefghijkl") We will then get the sub-string from the StringBuilder using substring() method from starting position of 5 in the character sequence of StringBuilder. In this example, we will create a StringBuilder object and initialize with some string passed as argument. Integer representing the start position of substring in StringBuilder. The syntax of substring() function is substring(int start)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |