Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

String subSequence in Java

by suresh

The Java String subSequence Method is used to return a new character sequence that is a subsequence of the user-specified string. In this article, we will show how to use String subSequence in Java Programming language with example.

Java String subSequence Syntax

The syntax of the string.subSequence in Java Programming language is as shown below.

The following method will accept the integer value that is the starting index position (Starting_index), where the extraction will start as the first parameter. And the last index position (End_index), where the character sequence will end as the second argument. String.subSequence method will return the character sequence starting from the Starting_index up to End_index but not included.

public CharSequence subSequence(int Startig_index, int End_index); // It will return Character Sequence 

//In order to use in program
String_Object.subSequence(int Startig_index, int End_Index)
  • String_Object: Please specify the valid String Object.
  • Starting_Index: Please specify the starting index position. It is the index position where the extraction of the character sequence will start.
  • End_Index: Please specify the ending index position. The String.subSequence function will return up to this index position, but it will not include the character at this position (End_index).

Example for String subSequence in Java

The string.subSequence method extracts the part of a string and returns in a new string. This program will help to understand the string.subSequence method.

//String. substring in Java example
package StringFunctions;

public class SubSequenceMethod {
	public static void main(String[] args) {
		String str = "Tutorials on Java Programming";
		String str1 = "We are abc working at abc company";
		
		System.out.println("subSequence of str = " + str.subSequence(0, 10));
		System.out.println("subSequence of str1 = " + str1.subSequence(0, 12));
		
		System.out.println("subSequence of str = " + str.subSequence(5, 10));
		System.out.println("subSequence of str1 = " + str1.subSequence(5, 12));
		
		System.out.println("subSequence of str = " + str.subSequence(6, str.length()));
		System.out.println("subSequence of str1 = " + str1.subSequence(5, str1.length()));
	}
}
String subSequence in Java 1

It will call the public CharSequence subSequence (int Starting_Index, int End_Index) method and return the character sequence starting from index 0 to index position 9

System.out.println("subSequence of str = " + str.subSequence(0, 10));

This statement will call the public CharSequence subSequence (int Starting_Index, int End_Index) method. And it returns the character sequence starting from index 5 to index position 9

System.out.println("subSequence of str = " + str.subSequence(5, 10));

The following String Method will return the character sequence starting from index 6 to the end of the string. Here, we used the Java String length function to find the string length

System.out.println("subSequence of str = " + str.subSequence(6, str.length()));

Placed Under: Java

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial

Copyright © 2021 · All Rights Reserved by Suresh

About Us | Contact Us | Privacy Policy