método HashSet class iterador () : Aquí, vamos a aprender sobre el método iterador () de HashSet Class con su sintaxis y su ejemplo.
HashSet Class iterador () método
- iterador () método está disponible en java.util Class.
- iterador () método se utiliza para iterar a todos los elementos que existen en este HashSet utilizando iterador método ().
- iterador () método es un método no class, es accesible sólo con el objeto package, y si tratamos de acceder al método con el nombre static entonces obtendrá un error.
- iterador () método no class una excepción en el momento de la iteración elementos HashSet.
Sintaxis:
public boolean isEmpty();
Parámetro (s):
- No acepta cualquier parámetro.
class valor:
El tipo throw del método es Iterator , devuelve un iterador sobre los objetos existen en este HashSet.
Ejemplo:
// Java program to demonstrate the example
// of boolean isEmpty () method of HashSet
import java.util.*;
public class IsEmptyOfHashSet {
public static void main(String[] args) {
// Instantiates a HashSet object
HashSet < String > hs = new HashSet < String > ();
// By using add() method is to add
// the given object of this
// HashSet
hs.add("C");
hs.add("C++");
hs.add("JAVA");
hs.add("PHP");
hs.add("SFDC");
// Display HashSet
System.out.println("HashSet: " + hs);
// By using isEmpty() method is
// to check whether this HashSet is
// empty or not
boolean status = hs.isEmpty();
// Display status
System.out.println("hs.isEmpty(): " + status);
}
}
salida
HashSet: [JAVA, C++, C, SFDC, PHP]
hs.isEmpty(): false