Método LinkedHashSet size() en Java

El método Java.util.LinkedHashSet.size() se usa para obtener el tamaño del LinkedHashSet o la cantidad de elementos presentes en el LinkedHashSet.

Sintaxis:

Linked_Hash_Set.size()

Parámetros: Este método no toma ningún parámetro.

Valor devuelto: el método devuelve el tamaño o la cantidad de elementos presentes en el LinkedHashSet.

El siguiente programa ilustra el método Java.util.LinkedHashSet.size():

// Java code to illustrate LinkedHashSet.size() method
import java.util.*;
import java.util.LinkedHashSet;
  
public class LinkedHashSetDemo {
    public static void main(String args[])
    {
        // Creating an empty LinkedHashSet
        LinkedHashSet<String> set = new LinkedHashSet<String>();
  
        // Use add() method to add elements into the Set
        set.add("Welcome");
        set.add("To");
        set.add("Geeks");
        set.add("4");
        set.add("Geeks");
  
        // Displaying the LinkedHashSet
        System.out.println("LinkedHashSet: " + set);
  
        // Displaying the size of the LinkedHashSet
        System.out.println("The size of the set is: "
                           + set.size());
    }
}
Producción:

LinkedHashSet: [Welcome, To, Geeks, 4]
The size of the set is: 4

Publicación traducida automáticamente

Artículo escrito por gopaldave y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *