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
substring(start,end) extracts part of string. - Indices are inclusive of start and exclusive of end. - Together demonstrates substring extraction. Conclusion: Shows how to extract substring from string.