String class substring methods. - Java Language Basics

Java examples for Language Basics:String

Description

String class substring methods.

Demo Code

public class Main 
{
   public static void main(String[] args)
   {//  ww  w.j a  va  2  s .  com
      String letters = "abcdefghijklmabcdefghijklm";

      // test substring methods
      System.out.printf("Substring from index 20 to end is \"%s\"\n",
         letters.substring(20));
      System.out.printf("%s \"%s\"\n", 
         "Substring from index 3 up to, but not including 6 is",
         letters.substring(3, 6));
   } 
}

Result


Related Tutorials