Net-informations.com
SiteMap  | About    

Java String substring()

Substring is a part of the String. Java String substring() method returns a new string object from a given String.

Syntax

String str = "Java String Tutorial";

String newStr = str.substring(5);

The above code returns "String Tutorial". That means the substring function extract the new string from 5th character (start index 5 ).

Example

Output

Syntax

The above method creates a new String object containing the contents of the existing String between two indices.

The above code returns "String", that means it extract the string from the 5th character to 11th character.

Example

Output

How to extract first 4 character from a string?

Output

How to extract last 8 characters from a String?

Output

How to print one char on each line?

Output









net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.