Home » Strings(We Suck Every1) » Substring Example

Substring Example

public class SubstringExample{

<em id="__mceDel"> public static void main(String[] args){
 // strings like arrays starts from zero...

 String string = "Rajesh kumar";
 System.out.println("String : " + string);

 String substring = string.substring(3); // start from that till end...
 System.out.println("String after 3rd index:" + substring);

 substring = string.substring(1, 4);
 System.out.println("Substring (1,4): " +substring);

 substring = string.substring(1, 2); // starts from 1 till <2
 System.out.println("Substring (1,2): " +substring);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: