How to get the Size of LinkedHashSet?
Previous | Home | Next |
In this program we saw how to get the size of the LinkedHashSet.
In this program we use public int size() of LikedHashSet class of java collections.It will return the size of number of elements in int datatype. or we can say in numbers.
The public int size() method is used here which will return the size of the set.
Simply call the size() method along with the object of LinkedHashSet which is created in this example.
package Example;
import java.util.LinkedHashSet;
import java .util.Iterator;
/**
* @author R4R
*
*/
public class IterateElements {
/**
* @param args
*/
public static void main(String[] args) {
LinkedHashSet Lhst = new LinkedHashSet();
Lhst.add("10");
Lhst.add("11");
Lhst.add("12");
Lhst.add("13");
Lhst.add("14");
Lhst.add("15");
Lhst.add("16");
System.out.println(" The LinkedHashSet contains the elements :"+Lhst);
Lhst.size();
System.out.println(" The size of the LinkedHashSet is:" + Lhst.size());
Lhst.clear();
Lhst.size();
System.out.println("All the elements from the set are removed: "+Lhst.isEmpty());
System.out.println(" The size of the LinkedHashSet is:" + Lhst.size());
// TODO Auto-generated method stub
}
}
The LinkedHashSet contains the elements :[10, 11, 12, 13, 14, 15, 16]
The size of the LinkedHashSet is:7
All the elements from the set are removed: true
The size of the LinkedHashSet is:0
Previous | Home | Next |