List of usage examples for java.util HashMap putAll
public void putAll(Map<? extends K, ? extends V> m)
From source file:Main.java
public static void main(String[] a) { HashMap<String, String> map = new HashMap<String, String>(); map.put("key1", "value1"); map.put("key2", "value2"); map.put("key3", "value3"); map.put(null, null);/*from ww w . ja va 2 s . c o m*/ HashMap<String, String> map2 = new HashMap<String, String>(); map2.put("key4", "value4"); map2.put("key5", "value5"); map2.put("key6", "value6"); map.putAll(map2); System.out.println(map); }
From source file:Main.java
public static void main(String args[]) { HashMap<Integer, String> newmap2 = new HashMap<Integer, String>(); HashMap<Integer, String> newmap1 = new HashMap<Integer, String>(); // populate hash map newmap1.put(1, "tutorials"); newmap1.put(2, "from"); newmap1.put(3, "java2s.com"); System.out.println("Values in newmap1: " + newmap1); // put all values in newmap2 newmap2.putAll(newmap1); System.out.println("Values in newmap2: " + newmap2); }
From source file:Main.java
public static <K, V> HashMap<K, V> toHashMap(Map<K, V> map) { HashMap<K, V> result = new HashMap<>(map.size()); result.putAll(map); return result; }
From source file:Main.java
/** * returns a new HashMap containing a shallow clone of the * original map.// www. j ava 2s . co m * @param origMap * @return */ public static <K, V> HashMap<K, V> clone(Map<K, V> origMap) { HashMap<K, V> newMap = new HashMap<K, V>(); if (origMap != null && origMap.size() > 0) { newMap.putAll(origMap); } return newMap; }
From source file:com.ecyrd.jspwiki.util.Serializer.java
/** * Serializes a Map and formats it into a Base64-encoded String. For ease of serialization, the Map contents * are first copied into a HashMap, then serialized into a byte array that is encoded as a Base64 String. * @param map the Map to serialize/* w ww. java 2s . c o m*/ * @return a String representing the serialized form of the Map * @throws IOException If serialization cannot be done */ public static String serializeToBase64(Map<String, Serializable> map) throws IOException { // Load the Map contents into a defensive HashMap HashMap<String, Serializable> serialMap = new HashMap<String, Serializable>(); serialMap.putAll(map); // Serialize the Map to an output stream ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bytesOut); out.writeObject(serialMap); out.close(); // Transform to Base64-encoded String byte[] result = Base64.encodeBase64(bytesOut.toByteArray()); return new String(result); }
From source file:com.dtolabs.rundeck.core.common.NodeEntryFactory.java
public static Map<String, String> toMap(final INodeEntry node) { HashMap<String, String> map = new HashMap<String, String>(); if (null != node.getAttributes()) { map.putAll(node.getAttributes()); }//from ww w. jav a 2s . c o m if (null == map.get("tags")) { map.put("tags", ""); } return map; }
From source file:com.opengamma.analytics.util.surface.StringValue.java
/** * Builder from a map. A new map is created with the same values. * @param map The map.// www . j a v a2 s .c om * @return The surface value. */ public static StringValue from(final Map<String, Double> map) { Validate.notNull(map, "Map"); HashMap<String, Double> data = new HashMap<String, Double>(); data.putAll(map); return new StringValue(data); }
From source file:com.opengamma.analytics.util.surface.StringValue.java
/** * Builder from a StringValue. A new map is created with the same values. * @param surface The StringValue/*from w w w .jav a 2s . co m*/ * @return The surface value. */ public static StringValue from(final StringValue surface) { Validate.notNull(surface, "Surface value"); HashMap<String, Double> data = new HashMap<String, Double>(); data.putAll(surface.getMap()); return new StringValue(data); }
From source file:Main.java
public static HashMap createComponentMap(Container ParentComponent) { // recursive add all sub-coponents into hashmap HashMap ComponentMap = new HashMap<String, Component>(); Component[] components = ParentComponent.getComponents(); for (Component comp : components) { if (comp instanceof Container) { ComponentMap.putAll(createComponentMap((Container) comp)); }//from ww w . jav a2s . c o m for (int i = 0; i < components.length; i++) { ComponentMap.put(components[i].getName(), components[i]); } } return ComponentMap; }
From source file:de.dakror.jagui.parser.NGuiParser.java
public static HashMap<String, File> collectGUIDs(File dir) throws Exception { HashMap<String, File> hash = new HashMap<>(); for (File f : dir.listFiles()) { if (f.isDirectory()) hash.putAll(collectGUIDs(f)); else if (f.getName().endsWith(".meta")) { File represents = new File(dir, f.getName().substring(0, f.getName().lastIndexOf(".meta"))); if (represents.exists()) { JSONObject o = new JSONObject((Map<?, ?>) new Yaml().load(new FileReader(f))); if (represents.getName().endsWith(".tga")) { Runtime.getRuntime() .exec("\"" + new File(DIR, "convert.exe").getPath() + "\" \"" + represents.getPath() + "\" \"" + represents.getParentFile().getPath() + "/" + represents.getName().replace(".tga", ".png") + "\""); hash.put(o.getString("guid"), new File(represents.getParentFile(), represents.getName().replace(".tga", ".png"))); } else hash.put(o.getString("guid"), represents); }/* w w w . j a va 2 s. c o m*/ } } return hash; }