
- Groovy Tutorial
- Groovy - Home
- Groovy - Overview
- Groovy - Environment
- Groovy - Basic Syntax
- Groovy - Data Types
- Groovy - Variables
- Groovy - Operators
- Groovy - Loops
- Groovy - Decision Making
- Groovy - Methods
- Groovy - File I/O
- Groovy - Optionals
- Groovy - Numbers
- Groovy - Strings
- Groovy - Ranges
- Groovy - Lists
- Groovy - Maps
- Groovy - Dates & Times
- Groovy - Regular Expressions
- Groovy - Exception Handling
- Groovy - Object Oriented
- Groovy - Generics
- Groovy - Traits
- Groovy - Closures
- Groovy - Annotations
- Groovy - XML
- Groovy - JMX
- Groovy - JSON
- Groovy - DSLS
- Groovy - Database
- Groovy - Builders
- Groovy - Command Line
- Groovy - Unit Testing
- Groovy - Template Engines
- Groovy - Meta Object Programming
- Groovy Useful Resources
- Groovy - Quick Guide
- Groovy - Useful Resources
- Groovy - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Groovy - subString()
Returns a new String that is a substring of this String. This method has 2 different variants
String substring(int beginIndex) − Pad the String with the spaces appended to the right.
Syntax
String substring(int beginIndex)
Parameters
beginIndex − the begin index, inclusive.
Return Value − The specified substring.
String substring(int beginIndex, int endIndex) − Pad the String with the padding characters appended to the right.
Syntax
String substring(int beginIndex, int endIndex)
Parameters
beginIndex − the begin index, inclusive.
endIndex − the end index, exclusive.
Return Value − The specified substring.
Example
Following is an example of the usage of both variants −
class Example { static void main(String[] args) { String a = "HelloWorld"; println(a.substring(4)); println(a.substring(4,8)); } }
When we run the above program, we will get the following result −
oWorld oWor
groovy_strings.htm
Advertisements