It makes sense when you realize what happens in the if-else construct.
In the first iteration, what do you think the nextElement() call in the if-condition returns, and how does it affect the current position of the StringTokenizer? Likewise, what would the effect of the nextToken() call in the else-body be?

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.

if block will advance the tokenizer to next token i.e from f->a then again from b->c that is the reason you are getting output as a\c\, never think compiler is wrong.! and according to you if you are not concentrating on if block then expected output should be f:\a\b\c

if block will advance the tokenizer to next token i.e from f->a then again from b->c that is the reason you are getting output as a\c\, never think compiler is wrong.! and according to you if you are not concentrating on if block then expected output should be f:\a\b\c