What is substring(int beginIndex, int endIndex) in Groovy?
substring(int beginIndex, int endIndex) is a function in Groovy that pads the String with the spaces added to the right.
Syntax
String substring(int beginIndex, int endIndex)
Parameters
The function takes in two parameters:
-
beginIndex: This is the beginning index (inclusive). -
endIndex: This is the ending index (exclusive).
Return value
The function returns the specified substring.
Code
class Example {static void main(String[] args) {String result = "Edpresso";println(result.substring(1,5));}
Output
dpre