‹ Back to the paper
Question 60
2 marks
Computer ScienceISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024)DifferentiateObjects
Differentiate between the following.
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
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().