String Handling- substring( )

substring( )

Syntax :-


 String substring (int index);String substring(int startIndex,int endIndex);

Substring() is an overloaded method, available in two version, first version of substring ( ) method of String class is used to retrieve part of string from the given index number to last index number and returns the resultant string. Second version of substring() method  is used to retrieve part of string from the invoking object.


class Example 1


public static void main (String arg[ ] )


String s1 =“Code project”;

String s2 =s1.substring(1);

String s3=s1.substring(1,4);






output :-

Code project

ode project


Leave a Reply

Your email address will not be published. Required fields are marked *