StringTokenizer countTokens() Method in Java with Examples Last Updated : 28 Jan, 2019 Comments Improve Suggest changes Like Article Like Report 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 method does not take any parameters. Return Value: The method is used to return the number of tokens remaining in the string using the current delimiter set. Below programs illustrate the working of countTokens() Method of StringTokenizer: Example 1: Java // Java code to illustrate countTokens() method import java.util.*; public class StringTokenizer_Demo1 { public static void main(String args[]) { // Creating a StringTokenizer StringTokenizer str_arr = new StringTokenizer( "Lets practice at GeeksforGeeks"); // Counting the tokens int count = str_arr.countTokens(); System.out.println("Total number of Tokens: " + count); // Print the tokens for (int i = 0; i < count; i++) System.out.println("token at [" + i + "] : " + str_arr.nextToken()); } } Output: Total number of Tokens: 4 token at [0] : Lets token at [1] : practice token at [2] : at token at [3] : GeeksforGeeks Example 2: Java // Java code to illustrate countTokens() method import java.util.*; public class StringTokenizer_Demo2 { public static void main(String args[]) { // Creating a StringTokenizer StringTokenizer str_arr = new StringTokenizer( "Welcome to GeeksforGeeks"); // Counting the tokens int count = str_arr.countTokens(); System.out.println("Total number of Tokens: " + count); // Print the tokens for (int i = 0; i < count; i++) System.out.println("token at [" + i + "] : " + str_arr.nextToken()); } } Output: Total number of Tokens: 3 token at [0] : Welcome token at [1] : to token at [2] : GeeksforGeeks Comment More infoAdvertise with us Next Article StringTokenizer countTokens() Method in Java with Examples chinmoy lenka Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-StringTokenizer +1 More Practice Tags : JavaMisc Similar Reads 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 Stream count() method in Java with examples long count() returns the count of elements in the stream. This is a special case of a reduction (A reduction operation takes a sequence of input elements and combines them into a single summary result by repeated application of a combining operation). This is a terminal operation i.e, it may travers 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 StringBuffer codePointCount() method in Java with Examples The codePointCount() method of StringBuffer class is used to return the number of Unicode code points in the specified range of beginIndex to endIndex of String contained by StringBuffer. This method takes beginIndex and endIndex as a parameter where beginIndex is the index of the first character of 3 min read Java String contains() Method with Example The String.contains() method is used to search for a sequence of characters within a string. In this article, we will learn how to effectively use the string contains functionality in Java.Example:In this example, we check if a specific substring is present in the given string.Java// Java Program to 3 min read StringCharacterIterator current() method in Java with Examples The current() method of java.text.StringCharacterIterator class in Java is used to get the current character that is to be read by this StringCharacterIterator. This method returns that current character. Syntax: public char current() Parameter: This method do not accept any parameter. Return Value: 1 min read StringTokenizer hasMoreTokens() Method in Java with Examples 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 2 min read StringBuffer delete() Method in Java with Examples The java.lang.StringBuffer.delete() is an inbuilt method in Java which is used to remove or delete the characters in a substring of this sequence. The substring starts at a specified index start_point and extends to the character at the index end_point. Syntax : public StringBuffer delete(int start_ 3 min read 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 Java streams counting() method with examples In Java 8, there is predefined counting() method returned by Collectors class counting() method to count the number of elements in a Stream. Syntax : public static Collector counting() Where, output is a Collector, acting on a Stream of elements of type T, with its finisher returning the âcollectedâ 2 min read Like