Java Challenge #9: Tokenizer

It is so important to know that Tokenizer exists and to know what tools you have available to make your code powerful!

Try to solve this challenge before seeing the answer below.

token.PNG

Answer: This is an easy one. We created the object Scanner passing the String to be tokenized, separated by a pattern. At first, you’ve got to know what the symbols on the tokens mean.

This symbol is called Regex. Many languages use the same concept:
http://www.vogella.com/tutorials/JavaRegularExpressions/article.html

In simple words, this symbol “^\\w” means “not a word” and the “*” means that – Occurs zero or more times, is short for {0,}, so it will tokenize by the comma “,“.

The result is:
ThisIsIt
theFinalString
NoBugsProject

Written by
Rafael del Nero
Join the discussion

2 comments

Stand Out as a Java Developer and Get Your Dream Job!

You will get the book by email in a few minutes after registering.