Java & OOP

String methods

Estimated reading: 1 minute 20 views

substring(0,2)

The substring() method in Java extracts a portion of a string based on start and end indices. It returns a new string from the original string, starting from the specified start index (inclusive) and ending at the end index (exclusive).
				
					String str = "Mahmut";
System.out.println(str.substring(0, 2));  // Output: "Ma"

				
			
				
					String str = "Data Structures";
System.out.println(str.substring(5));     // Output: "Structures"

				
			
Share this Doc

String methods

Or copy link

CONTENTS