You could try Apache Commons Lang's StringUtils class, which can split a string while ignoring empty elements and handling null
strings for you.
A tokenizer would have to read at least n tokens in order to determine which is the n-th one. Thus it might be easier to just create a string array using String#split()
or StringUtils.split(...)
.
Note that I'd prefer StringUtils.split(...)
since it doesn't return empty elements if I don't want them, i.e. StringUtils.split(",a,b,c;;d,e,,f",";,");
would return ["a","b","c","d","e","f"]
whereas String#split()
would return ["","a","b","c","","d","e","","f"]