Example usage for java.util LinkedHashMap LinkedHashMap

List of usage examples for java.util LinkedHashMap LinkedHashMap

Introduction

In this page you can find the example usage for java.util LinkedHashMap LinkedHashMap.

Prototype

public LinkedHashMap() 

Source Link

Document

Constructs an empty insertion-ordered LinkedHashMap instance with the default initial capacity (16) and load factor (0.75).

Usage

From source file:Main.java

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

    lHashMap.put("One", new Integer(1));
    lHashMap.put("Two", new Integer(2));

    Object obj = lHashMap.get("One");
    System.out.println(obj);//  w w  w  .  ja v a  2 s .  c  om
}

From source file:Main.java

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", "Three");

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

From source file:Main.java

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", "Three");

    boolean blnExists = lHashMap.containsValue("Two");
    System.out.println(blnExists);
}

From source file:Main.java

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", "Three");

    lHashMap.clear();/*from   w  w  w. ja  v  a  2s  . com*/
    System.out.println(lHashMap.size());

}

From source file:MainClass.java

public static void main(String[] args) {
    LinkedHashMap linkedMap = new LinkedHashMap();
    for (int i = 0; i < 10; i++) {
        linkedMap.put(i, i);/*  www  .j  av  a 2s.  c  o m*/
    }

    System.out.println(linkedMap);
    // Least-recently used order:
    linkedMap = new LinkedHashMap(16, 0.75f, true);

    for (int i = 0; i < 10; i++) {
        linkedMap.put(i, i);
    }
    System.out.println(linkedMap);
    for (int i = 0; i < 7; i++)
        // Cause accesses:
        System.out.println(linkedMap.get(i));
    System.out.println(linkedMap);
}

From source file:Main.java

public static void main(String[] args) {

    LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>();

    // add some values in the map
    map.put("One", 1);
    map.put("Two", 2);
    map.put("Three", 3);

    System.out.println(map);/*from   w w w .  ja  va 2  s.c  o  m*/

    // clear the map
    map.clear();

    System.out.println(map);
}

From source file:Main.java

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

    System.out.println(lHashMap.size());

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

    System.out.println(lHashMap.size());

    Object obj = lHashMap.remove("2");
    System.out.println(lHashMap.size());

}

From source file:Main.java

public static void main(String[] args) {
    Map<String, Integer> map = new LinkedHashMap<>();

    map.put("Zero", 0);
    map.put("One", 1);
    map.put("Two", 2);
    map.put("Three", 3);
    map.put("Four", 4);

    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        System.out.println(entry.getKey() + " => " + entry.getValue());
    }/*from  w  w  w  .  j ava  2  s  .co  m*/
}

From source file:Main.java

public static void main(String[] args) {
    LinkedHashMap<Integer, Integer> linkedMap = new LinkedHashMap<Integer, Integer>();
    for (int i = 0; i < 10; i++) {
        linkedMap.put(i, i);/*  ww  w.  ja va 2s .  co  m*/
    }

    System.out.println(linkedMap);
    // Least-recently used order:
    linkedMap = new LinkedHashMap<Integer, Integer>(16, 0.75f, true);

    for (int i = 0; i < 10; i++) {
        linkedMap.put(i, i);
    }
    System.out.println(linkedMap);
    for (int i = 0; i < 7; i++)
        System.out.println(linkedMap.get(i));
    System.out.println(linkedMap);
}

From source file:Main.java

public static void main(String[] args) {
    Map<String, Integer> wordCounts = new LinkedHashMap<String, Integer>();

    String s = "Lorem ipsum dolor sit amet consetetur iam nonumy sadipscing "
            + "elitr, sed diam nonumy eirmod tempor invidunt ut erat sed "
            + "labore et dolore magna dolor sit amet aliquyam erat sed diam";

    wordCounts.put("sed", 0);
    wordCounts.put("erat", 0);

    for (String t : s.split(" ")) {
        wordCounts.computeIfPresent(t, (k, v) -> v + 1);
    }/*from  w  w w  .j a  va2 s.c o  m*/
    System.out.println(wordCounts);
}