Java String split example source code

In this section, we will be showing on how to split string value into tokens in java. String object has a split() method. This method can take an argument a regex pattern. Here is a sample java code that makes use of split method to tokenize a given string.

Running the script above will give you the following output:

The input string is “01 02 03 04656 TEST” and has been assigned to variable input which in turn to be of type String. The regex pattern that we use is a space. The tokenize string is of type String[] thus the for loop to access the value and display the tokenize string into our console.

Suggested Reading List:

Comments are closed