El método size() de la interfaz SortedSet se utiliza para obtener el tamaño del SortedSet o el número de elementos presentes en el SortedSet.
Sintaxis:
int 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 SortedSet.
Nota : El método size() en SortedSet se hereda de la interfaz Set en Java.
El siguiente programa ilustra el método java.util.Set.size():
// Java code to illustrate Set.size() method import java.util.*; public class SetDemo { public static void main(String args[]) { // Creating an empty Set SortedSet<String> set = new TreeSet<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 Set System.out.println("Set: " + set); // Displaying the size of the Set System.out.println( "The size of the SortedSet is: " + set.size()); } }
Producción:
Set: [4, Geeks, To, Welcome] The size of the SortedSet is: 4
Referencia : https://docs.oracle.com/javase/7/docs/api/java/util/Set.html#size()