Java LinkedHashMap.clear()

Syntax

LinkedHashMap.clear() has the following syntax.

public void clear()

Example

In the following code shows how to use LinkedHashMap.clear() method.


import java.util.LinkedHashMap;
//from   ww w.  j  a  v  a2  s .c om
public class Main {

   public static void main(String[] args) {

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

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


      System.out.println(map);

      // clear the map
      map.clear();


      System.out.println(map);
   }
}

The code above generates the following result.