Splitting a Strings is common operation. This short tutorial will show some of the ways to complete is operation.
Let’s try a few examples. First we’ll start with splitting by a common:
Split By a Whitespace:
Split By a Period:
String.split() with Limits
You can limit the size of the array return by passing a limit value to the split() method.
Let’s try a few examples. First we’ll return an array with two element:
Split returns array with 3 elements:
This tutorial cover different ways you can split a string in Java. You can find more tutorials on Java here
The source examples can be found here on GitHub.