java tutorial - Java Strings substring() method - java programming - learn java - java basics - java for beginners



Java strings substring

Learn Java - Java tutorial - Java strings substring - Java examples - Java programs

Description

The substring () method in Java has two options and returns a new string, which is a substring of this string. The substring starts with the character specified by the index, and continues to the end of this line or to endIndex-1, if a second argument is entered.

Syntax

Syntax method:

public String substring(int beginIndex)

or

public String substring(int beginIndex, int endIndex)
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • beginIndex - initial index, inclusive;
  • endIndex - end index, not including.

Return value

  • A Java substring() the return value is specified by a substring.

Sample Code

import java.io.*;
public class Test {

public static void main(String args []) {
String Str = new String("Welcome to wikitechy.com");

System.out.print("Return Value:");
System.out.println (Str.substring (5));

System.out.print("Return Value:");
System.out.println (Str.substring (5, 15));
}
}
click below button to copy the code. By - java tutorial - team

Output

Return Value:me to wikitechy.com
Return Value:me to wiki

Related Searches to Java Strings substring() method