I need to split a string that is "Kermit D.Frogge"
, so this is the code I've used:
firstName = strTkn.nextToken();
middleInitial = strTkn.nextToken(".");
//changing the delimiters to a . because there is no space between D and Frogge
lastName = strTkn.nextToken(" ");
//changing delimiters back to a space
hourlyWage = Double.parseDouble(strTkn.nextToken());
However, the result is:
Kermit
D
.Frogge
How would I use string tokenizer and not keep the period?
Use the constructor with two arguments. The second argument is a string whose characters are delimiters.
StringTokenizer st = new StringTokenizer(string, " .");