bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java String substring() Method

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Java String substring() Method?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ myStr = "Hello, World!";
3Order

Put the learning moves in the order that makes the concept easiest to apply.

The substring() method returns a substring from the string.
Definition and Usage
Java String substring() Method

❮ String Methods

Example

String myStr = "Hello, World!";
System.out.println(myStr.substring(7, 12));

Definition and Usage

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

If the end argument is not specified then the substring will end at the end of the string.

One of the following

public String substring(int
start , int
end )
public String substring(int
start )

Parameter Values

ParameterDescription
startRequired. The index of the character at which the substring starts.
endOptional. The index after the last character of the substring.

Technical Details

Returns:A String containing a substring of the string.
Throws:IndexOutOfBoundsException - If start or end are negative or they are greater than the length of the string or if start is greater than end .
Java version:Any

Previous

Java String subSequence() Method

Next

Java String toCharArray() Method