Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
StringTokenizer hasMoreElements() Method in Java with Examples
Next article icon

StringTokenizer hasMoreTokens() Method in Java with Examples

Last Updated : 28 Jan, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report

The hasMoreTokens() method of StringTokenizer class checks whether there are any more tokens available with this StringTokenizer.

Syntax:

public boolean hasMoreTokens()

Parameters: The method does not take any parameters.

Return Value: The method returns boolean True if the availability of at least one more token is found in the string after the current position else false.

Below programs illustrate the working of hasMoreTokens() Method of StringTokenizer:
Example 1:




// Java code to illustrate hasMoreTokens() method
  
import java.util.*;
  
public class StringTokenizer_Demo {
    public static void main(String args[])
    {
        // Creating a StringTokenizer
        StringTokenizer str_arr
            = new StringTokenizer(
                "Lets practice at GeeksforGeeks");
  
        // Counting the tokens
        System.out.println("The number of Tokens are: "
                           + str_arr.countTokens());
  
        // Checking for any tokens
        System.out.println(str_arr.hasMoreTokens());
  
        // Checking and displaying the Tokens
        while (str_arr.hasMoreTokens()) {
            System.out.println("The Next token: "
                               + str_arr.nextToken());
        }
    }
}
 
 
Output:
  The number of Tokens are: 4  true  The Next token: Lets  The Next token: practice  The Next token: at  The Next token: GeeksforGeeks  

Example 2:




// Java code to illustrate hasMoreTokens() method
  
import java.util.*;
  
public class StringTokenizer_Demo {
    public static void main(String args[])
    {
        // Creating a StringTokenizer
        StringTokenizer str_arr
            = new StringTokenizer("");
  
        // Counting the tokens
        System.out.println("The number of Tokens are: "
                           + str_arr.countTokens());
  
        // Checking for any tokens
        System.out.println(str_arr.hasMoreTokens());
    }
}
 
 
Output:
  The number of Tokens are: 0  false  


Next Article
StringTokenizer hasMoreElements() Method in Java with Examples
author
chinmoy lenka
Improve
Article Tags :
  • Java
  • Java - util package
  • Java-Functions
  • Java-StringTokenizer
Practice Tags :
  • Java

Similar Reads

  • StringTokenizer hasMoreElements() Method in Java with Examples
    The hasMoreElements() method of StringTokenizer class also checks whether there are any more tokens available with this StringTokenizer. It is similar to the hasMoreTokens(). The method exists exclusively so that the Enumeration interface of this class can be implemented. Syntax: public boolean hasM
    2 min read
  • StringTokenizer nextToken() Method in Java with Examples
    The nextToken() method of StringTokenizer class is used to return the next token one after another from this StringTokenizer. Syntax: public String nextToken() Parameters: The method does not take any parameters. Return Value: The method returns the next token present in the line of the string token
    1 min read
  • Scanner hasNextLong() method in Java with Examples
    The hasNextLong() method of java.util.Scanner class returns true if the next token in this scanner's input can be assumed as a Long value of the given radix. The scanner does not advance past any input. In case no radix is passed as a parameter, the function interprets the radix to be default radix
    3 min read
  • Scanner hasNextBoolean() method in Java with Examples
    The hasNextBoolean() method of java.util.Scanner class returns true if the next token in this scanner's input can be interpreted as a Boolean using the nextBoolean() method. The scanner does not advance past any input. Syntax: public boolean hasNextBoolean() Parameters: The function does not accepts
    2 min read
  • Scanner hasNextInt() method in Java with Examples
    The hasNextInt() method of java.util.Scanner class returns true if the next token in this scanner's input can be assumed as a Int value of the given radix. The scanner does not advance past any input. In case no radix is passed as a parameter, the function interprets the radix to be default radix an
    3 min read
  • Scanner hasNextDouble() method in Java with Examples
    The hasNextDouble() method of java.util.Scanner class returns true if the next token in this scanner's input can be interpreted as a Double using the nextDouble() method. The scanner does not advance past any input. Syntax: public Double hasNextDouble() Parameters: The function does not accepts any
    2 min read
  • StringTokenizer countTokens() Method in Java with Examples
    The countTokens() method of StringTokenizer class calculate the number of times that this tokenizer's nextToken method can be called before the method generates any further exception. Note: The current position is not advanced during the process. Syntax: public int countTokens() Parameters: The meth
    2 min read
  • StringTokenizer nextElement() Method in Java with Examples
    The nextElement() method of StringTokenizer class is also used to return the next token one after another from this StringTokenizer. It is similar to the nextToken() method, except that the return type is Object rather than the String. Syntax: public Object nextElement() Parameters: The method does
    2 min read
  • StringCharacterIterator hashCode() method in Java with Examples
    The hashCode() method of java.text.StringCharacterIterator class in Java is used to get the hashCode value of this StringCharacterIterator. This method returns an integer representing the hashCode value. Syntax: public int hashCode() Parameter: This method do not accept any parameter. Return Value:
    1 min read
  • Scanner hasNextShort() method in Java with Examples
    The hasNextShort() method of java.util.Scanner class returns true if the next token in this scanner's input can be assumed as a short value of the given radix. The scanner does not advance past any input. In case no radix is passed as a parameter, the function interprets the radix to be default radi
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences