In this tutorial, we are going to learn about how to remove the first 3 characters of a string in Java.
To remove the first 3 characters of a string, we can use the built-in substring() method by passing the 3 as a argument to it.
Here is an example:
String str = "123Hello"; String result = str.substring(3); System.out.println(result);
In the example above, we have passed the
3 as argument to the substring() method. so it begins the extraction at index position
3 and extracts to the end of a string.
It begins the extraction at startIndex and goes upto the stopindex-1, if we don’t provide the endIndex it begins the extraction at specified index extracts upto to the end of a string.
substring() method doesn’t mutates the original string, instead of it creates a new one with the extracted characters.