Extract Substring
This program extracts substring from a string.
Problem Statement
Write a Java program to extract substring from index 2 to 5.
Source Code
| 1 | public class SubstringExtraction { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Substring Extraction"); |
| 4 | String str="EduinqString"; |
| 5 | String sub=str.substring(2,6); |
| 6 | System.out.println("Extracted substring: "+sub); |
| 7 | } |
| 8 | } |
Program Output
Eduinq Substring Extraction Extracted substring: uinq
Explanation
The substring(start, end) method extracts a portion of the string, where the start index is inclusive and the end index is exclusive, demonstrating substring extraction.