Detecting tokens (words) using Java