Obtaining a Subsection of a String - Java Language Basics

Java examples for Language Basics:String

Introduction

Use the substring() method to obtain a portion of the String between two different positions.

Demo Code

public class Main {
    public static void main(String[] args){

        String originalString = "This is the original String";
        System.out.println(originalString.substring(0, originalString.length()));
        System.out.println(originalString.substring(5, 20));
        System.out.println(originalString.substring(12));
    }/* w  ww .  ja  va 2 s  .  com*/
}

Result


Related Tutorials