Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

subSequence()

Example

Extract a consecutive series of characters from within a string.

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

Definition and Usage

The method subSequence() retrieves a subset of characters from the string and returns it as a CharSequence object.

Syntax

public CharSequence subSequence(int start, int end)

Parameter Values

Parameter

Description

start

Necessary: Provide the index of the character where the subsequence begins.

end

Necessary: Specify the index immediately following the last character of the subsequence.

Technical Details

Returns

CharSequence containing a portion of the original string

Throws

The IndexOutOfBoundsException occurs when either the start or end parameters are negative, when start exceeds end, or when end surpasses the length of the string.

Java Version

1.4