Get Size of Java LinkedHashSet - Java Collection Framework

Java examples for Collection Framework:LinkedHashSet

Description

Get Size of Java LinkedHashSet

Demo Code


import java.util.LinkedHashSet;
 
public class Main {
 
  public static void main(String[] args) {
    LinkedHashSet lhashSet = new LinkedHashSet();
    System.out.println("Size of LinkedHashSet : " + lhashSet.size());
 
    lhashSet.add(new Integer("1"));
    lhashSet.add(new Integer("2"));
    lhashSet.add(new Integer("3"));
 
    System.out.println("Size of LinkedHashSet after addition : " + lhashSet.size());
 
    //remove one element from LinkedHashSet using remove method
    lhashSet.remove(new Integer("1"));
    System.out.println("Size of LinkedHashSet after removal : " + lhashSet.size());
  }//  ww  w . ja  v a  2s  .co m
}

Result


Related Tutorials