Java Map get key set

Description

Java Map get key set

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class Main {

  public static void main(String[] args) {
    Map<String, String> m1 = new LinkedHashMap<String, String>();
    m1.put("CSS", "One");
    m1.put("HTML", "Three");

    Map<String, String> m2 = new LinkedHashMap<String, String>();
    m2.put("SQL", "Two");
    m2.put("Java", "Four");

    List<String> list = new ArrayList<String>();
    list.addAll(m1.keySet());//w w  w. j a v a  2  s.c  o m
    list.addAll(m2.keySet());
    
    for (String s : list) {
      System.out.println(s);
    }
  }

}



PreviousNext

Related