I have a String with delimiter (~
)
String str="ABC~DEF~GHI~JKL~~MNO";// Input String
while(stk.hasMoreTokens()){
obj[i]=stk.nextToken();
i++;
}
for(Object ob:obj){
System.out.print(ob+"~>");
}
I am using StringTokenizer to break String into Tokens, but whenever consecutive delimeter
comes in between without any Space
then StringTokenizer
skips it and take the next Token
Actual Output
ABC~>DEF~>GHI~>JKL~>MNO~>null~>
Desired Outupt
ABC~>DEF~>GHI~>JKL~>null~>MNO~> // Don't want to skip consecutive tokens
Why this is happening ?
Note :
I know i can get the desired output using String#split(String delimeter)
method but , i want to know the root cause why there is a Strange Behaviour.
Same Question has been asked here (String Tokenizer issue) but no reason was provided , only alternative solutions are there