Groovy String drop() examples

While exploring groovy langauge, I noticed two String methods take and drop. Both provide ways to get substring of a String. In this post, we discuss Groovy String drop method and ow to use it.


Here is the simple syntax of drop method in the Groovy String class.
public static CharSequence drop(int num)
What this method do is the opposite of take. Take returns the first num characters. But this method removes them! So it returns the String without the first num characters.

How to use

See below example on how to use the drop method of Groovy String.

def text = "abcd"
println text.drop( 2 )

We have the String abcd and we remove the first 2 characters. So we get


Pretty simple and straight forward. Gotta love Groovy!