Enumeration hasMoreElements() Method in Java with Examples Last Updated : 27 Jun, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report An object that implements the Enumeration interface generates a series of elements, one at a time. hasMoreElements() method of Enumeration used to tests if this enumeration contains more elements. If enumeration contains more element then it will return true else false. Syntax: boolean hasMoreElements() Parameters: This method accepts nothing. Return value: This method returns true if and only if this enumeration object contains at least one more element to provide; false otherwise. Below programs illustrate hasMoreElements() method: Program 1: Java // Java program to demonstrate // Enumeration.hasMoreElements() method import java.util.*; public class GFG { @SuppressWarnings({ "unchecked", "rawtypes" }) public static void main(String[] args) { Enumeration Days; Vector week = new Vector(); week.add("Sunday"); week.add("Monday"); week.add("Tuesday"); week.add("Wednesday"); week.add("Thursday"); week.add("Friday"); week.add("Saturday"); Days = week.elements(); while (Days.hasMoreElements()) { System.out.println("Day = " + Days.nextElement()); } } } Output: Day = Sunday Day = Monday Day = Tuesday Day = Wednesday Day = Thursday Day = Friday Day = Saturday Program 2: Java // Java program to demonstrate // Enumeration.hasMoreElements() method import java.util.*; public class GFG { @SuppressWarnings({ "unchecked", "rawtypes" }) public static void main(String[] args) { Enumeration<Integer> classNine; Vector<Integer> rollno = new Vector<Integer>(); rollno.add(1); rollno.add(2); rollno.add(3); rollno.add(4); rollno.add(5); rollno.add(6); rollno.add(7); rollno.add(8); classNine = rollno.elements(); while (classNine.hasMoreElements()) { System.out.println("Roll No = " + classNine.nextElement()); } } } Output: Roll No = 1 Roll No = 2 Roll No = 3 Roll No = 4 Roll No = 5 Roll No = 6 Roll No = 7 Roll No = 8 References: https://docs.oracle.com/javase/10/docs/api/java/util/Enumeration.html#hasMoreElements() Comment More infoAdvertise with us Next Article HashSet containsAll() method in Java with Example A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions Java-Enumeration 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 Collections enumeration() method in Java with Examples The enumeration() method of java.util.Collections class is used to return an enumeration over the specified collection. This provides interoperability with legacy APIs that require an enumeration as input.Syntax: public static Enumeration enumeration(Collection c) Parameters: This method takes the c 2 min read HashSet containsAll() method in Java with Example The containsAll() method of Java HashSet is used to check whether two sets contain the same elements or not. It takes one set as a parameter and returns True if all of the elements of this set is present in the other set. Syntax: public boolean containsAll(Collection C) Parameters: The parameter C i 2 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 Set contains() method in Java with Examples The Java.util.Set.contains() method is used to check whether a specific element is present in the Set or not. So basically it is used to check if a Set contains any particular element. Syntax: boolean contains(Object element) Parameters: The parameter element is of the type of Set. This is the eleme 2 min read Java Collections emptyEnumeration()â Method with Examples The emptyEnumeration() method of Java Collections is used to get the empty enumeration that contains no elements in Java. Syntax: public static <T> Enumeration<T> emptyEnumeration() Parameters: This method has no parameters. Return Type: This method will return an empty enumeration. Exce 2 min read Like