‹ Back to the paper
What is the difference between the two methods, `nextToken( )` and `hasMoreTokens( )` of…
What is the difference between the two methods, `nextToken( )` and `hasMoreTokens( )` of StringTokenizer class ?
Answer
Answer
AInextToken() returns the next token from the StringTokenizer as a String, and moves past it.
hasMoreTokens() returns a boolean (true/false) indicating whether at least one more token remains; it does not consume a token, and is normally used to test the condition of a loop (e.g. while(st.hasMoreTokens())) before calling nextToken().
From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 60.