Get Set view of Keys from LinkedHashMap in Java

Description

The following code shows how to get Set view of Keys from LinkedHashMap.

Example


/* ww  w . j  av a  2  s. c o m*/
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Set;

public class Main {
  public static void main(String[] args) {
    LinkedHashMap<String,String> lHashMap = new LinkedHashMap<String,String>();

    lHashMap.put("1", "One");
    lHashMap.put("2", "Two");
    lHashMap.put("3", "java2s.com");

    Set st = lHashMap.keySet();

    Iterator itr = st.iterator();

    while (itr.hasNext()){
      System.out.println(itr.next());
    }
    st.remove("2");

    boolean blnExists = lHashMap.containsKey("2");
    System.out.println(blnExists);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Java Collection »




Java ArrayList
Java Collection
Java Comparable
Java Comparator
Java HashMap
Java HashSet
Java Iterator
Java LinkedHashMap
Java LinkedHashSet
Java LinkedList
Java List
Java ListIterator
Java Map
Queue
Java Set
Stack
Java TreeMap
TreeSet