Write a Java program to get a substring of a given string between two specified positions.

Java Programming Language / String in java

2144

Program:

public class Exercise {

   public static void main(String[] args)
    {
        String str = "The quick brown fox jumps over the lazy dog.";

        // Get a substring of the above string starting from
        // index 10 and ending at index 26.
        String new_str = str.substring(10, 26);

        // Display the two strings for comparison.
        System.out.println("old = " + str);
        System.out.println("new = " + new_str);
    }
}

Output:

old = The quick brown fox jumps over the lazy dog.
new = brown fox jumps
Press any key to continue . . .

Explanation:

None

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.