Java substring() Method

Java String类Java String Class


The substring() method returns a substring of the string.

Syntax

public String substring(int beginIndex)

或

public String substring(int beginIndex, int endIndex)

Parameters

  • beginIndex-- start index (inclusive), index starts from 0.

  • endIndex-- end index (exclusive).

Return Value

The substring.

Example

public class ExampleTest { public static void main(String args[]) { String Str = new String("This is text"); System.out.print("Return Value :" ); System.out.println(Str.substring(4) ); System.out.print("Return Value :" ); System.out.println(Str.substring(4, 10) ); } }

The above program execution result is:

返回值 : is text
返回值 : is te

Java String类Java String Class

Other Extensions