O'Reilly logo

Java 9 Regular Expressions by Anubhava Srivastava

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Example of the split method using the limit parameter

To understand the impact of the limit parameter, let's take a comma-separated input string with two trailing commas:

fox,tiger,wolf,, 

We can call the split method in two ways. We can call the split method with limit=0:

String[] arr = input.split(",", 0); 

We can also call the single parameter split method call as:

String[] arr = input.split(","); 

It splits the input string around a comma and the trailing empty strings are discarded, with the following values being returned by the split method:

"fox" "tiger" "wolf" 

Now, let's call the split method with limit=1:

String[] arr = input.split(",", 1); 

It splits the input string around a comma and then gets a single element in the resulting ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required