Get Sub string from whole string - Java Language Basics

Java examples for Language Basics:String

Description

Get Sub string from whole string

Demo Code


public class Main {
 
  public static void main(String args[]){
      String name="Hello World";
     //from  w  ww .j av a 2s  . co m
      /*print the substring starting from index 6*/
      System.out.println(name.substring(6));
     
      /*print the substring starting from index 0 upto 4 not 5.
        startIndex is inclusive while endIndex is exclusive.
      */
      System.out.println(name.substring(0,5));
 
  }
 
}

Result


Related Tutorials