PRASHNIKAप्रश्निका
‹ Back to the paper

What is the difference between the two methods, `nextToken( )` and `hasMoreTokens( )` of…

Computer Science20252 marksShort answer
What is the difference between the two methods, `nextToken( )` and `hasMoreTokens( )` of StringTokenizer class ?

Answer

Answer

AI
nextToken() 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().
Objects

From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 60.