Java String substring() method example | java substring
TheString[1]substring()methodreturnsanewstringthatisasubstringofthegivenstring.substring()usesthestartandoptionallytheendindices,passedasmethodarguments,todeterminethesubstringpositionwithintheoriginalstring.Stringsubstring(intbeginIndex)Stringsubstring(intbeginIndex,intendIndex)Stringtext="LoremIpsumissimplydummytext";Stringsubstring=text.substring(5);Stringsubstring=text.substring(3,10);1.Stringsubstring()MethodThesubstring()methodinthejava.lang.Stringclassisanoverloadedmethod:Stringsubst...
The String[1] substring() method returns a new string that is a substring of the given string.
substring() uses the start and optionally the end indices, passed as method arguments, to determine the substring position within the original string.
String substring(int beginIndex) String substring(int beginIndex, int endIndex) String text = "Lorem Ipsum is simply dummy text"; String substring = text.substring(5); String substring = text.substring(3, 10); 1. String substring() MethodThe substring() method in the java.lang.String class is an overloaded method:
String substring(int beginIndex) String substring(int beginIndex, int endIndex) Method ParametersThe substring() method arguments are:
beginIndex – the beginning index, inclusive.endIndex – the ending index, exclusive.Return ValueIt returns the substring from the given string.
2. Find substring with the begin indexSupply only begin index when we need to find a substring starting from the given in...