Enumeration hasMoreElements() Method in Java with Examples Last Updated : 27 Jun, 2019 Comments Improve Suggest changes 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 Enumeration hasMoreElements() Method in Java with Examples 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 Buffer hasRemaining() methods in Java with Examples The hasRemaining() method of java.nio.Buffer class is used to tell whether there are any elements between the current position and the limit. Syntax: public final boolean hasRemaining() Returns: This method will return true if, and only if, there is at least one element remaining in this buffer. Bel 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 Collection add() Method in Java with Examples The add(E element) of java.util.Collection interface is used to add the element 'element' to this collection. This method returns a boolean value depicting the successfulness of the operation. If the element was added, it returns true, else it returns false. Syntax: Collection.add(E element) Paramet 4 min read Like