String Tokenization

pom.xml:

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.6</version>
        </dependency>

StringTokenization.java: 

import org.apache.commons.lang3.StringUtils;

public class StringTokenization{
        public static void main(String[] args) {
              String string = "Hello, welcome to the MMR Blog";
              getTokens(string);
        }
private static void getTokens(String str) {
        try {
            String[] tokens = StringUtils.split(str, " ");
            int count = 0;
            for (String token : tokens) {
                System.out.println("The token [" + count++ + "]:" + token);
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}

Comments