List of usage examples for java.util HashMap put
public V put(K key, V value)
From source file:Main.java
public static void main(String args[]) { HashMap<String, String> hmap = new HashMap<String, String>(); hmap.put("1", "A"); hmap.put("2", "B"); hmap.put("3", "C"); hmap.put("4", "from java2s.com"); // get typesafe view of the map Map<String, String> tsmap = Collections.checkedMap(hmap, String.class, String.class); System.out.println(tsmap);/*from w w w .j a v a 2 s . c om*/ }
From source file:Main.java
public static void main(String[] args) { HashMap<String, String> hMap = new HashMap<String, String>(); hMap.put("1", "One"); hMap.put("2", "Two"); hMap.put("3", "Three"); Collection c = hMap.values(); Iterator itr = c.iterator();//from w w w.j av a 2 s . co m while (itr.hasNext()) { System.out.println(itr.next()); } }
From source file:Main.java
public static void main(String args[]) { HashMap<Integer, String> newmap = new HashMap<Integer, String>(); newmap.put(1, "tutorials"); newmap.put(2, "from"); newmap.put(3, "java2s.com"); // create set view for the map Set set = newmap.entrySet();//from www . j av a 2s . co m // check set values System.out.println("Set values: " + set); }
From source file:Main.java
public static void main(String[] args) { HashMap<String, Integer> myMap = new HashMap<String, Integer>(); myMap.put("a", 1); myMap.put("b", 2); myMap.put("c", 3); Set<String> stStrKeys = myMap.keySet(); Iterator<String> itrs = stStrKeys.iterator(); while (itrs.hasNext()) { String s = itrs.next();//from www . j a v a 2 s . com System.out.println(s + ": " + myMap.get(s)); } }
From source file:Main.java
public static void main(String[] args) { HashMap<String, Integer> map = new HashMap<String, Integer>(); map.put("a", 1); map.put("b", 2); System.out.println("Before removal"); for (String s : map.keySet()) { System.out.println(s);//from w w w . ja va2 s. c o m } System.out.println("\n\nAfter removal"); map.remove("a"); for (String s : map.keySet()) { System.out.println(s); } }
From source file:Main.java
public static void main(String[] args) { HashMap<String, String> hMap = new HashMap<String, String>(); hMap.put("1", "One"); hMap.put("2", "Two"); hMap.put("3", "Three"); Set st = hMap.keySet();//from w w w.java 2s . com Iterator itr = st.iterator(); while (itr.hasNext()) System.out.println(itr.next()); // remove 2 from Set st.remove("2"); System.out.println(hMap.containsKey("2")); }
From source file:Main.java
public static void main(String a[]) { HashMap hashMap = new HashMap(); HashMap hashMap1 = new HashMap(); hashMap.put(1, "One"); hashMap.put(2, "Two"); hashMap.put(3, "Three"); System.out.println("Original HashMap : " + hashMap); hashMap1 = (HashMap) hashMap.clone(); System.out.println("Copied HashMap : " + hashMap1); }
From source file:HashMapDemo.java
public static void main(String args[]) { HashMap<String, Double> hm = new HashMap<String, Double>(); hm.put("A", new Double(3.34)); hm.put("B", new Double(1.22)); hm.put("C", new Double(1.00)); hm.put("D", new Double(9.22)); hm.put("E", new Double(-19.08)); Set<Map.Entry<String, Double>> set = hm.entrySet(); for (Map.Entry<String, Double> me : set) { System.out.print(me.getKey() + ": "); System.out.println(me.getValue()); }/*www .j a v a 2 s . co m*/ double balance = hm.get("A"); hm.put("A", balance + 1000); System.out.println(hm.get("A")); }
From source file:CopyPDFFileAndAddMetaData.java
public static void main(String[] args) { try {/*w ww . ja va2 s. c om*/ PdfReader reader = new PdfReader("YourOwnPDF.pdf"); PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("NewPDFFileFromPdfStamper.pdf")); HashMap<String, String> moreInfo = new HashMap<String, String>(); moreInfo.put("Author", "YourName"); moreInfo.put("Title", "YourTitle"); moreInfo.put("Subject", "YourSubject"); stamp.setMoreInfo(moreInfo); stamp.close(); } catch (Exception de) { de.printStackTrace(); } }
From source file:HelloWorldAddMetadata.java
public static void main(String[] args) throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf")); document.open();/* w w w. java2 s. c om*/ document.add(new Paragraph("Hello World")); document.close(); PdfReader reader = new PdfReader("HelloWorld.pdf"); System.out.println("Tampered? " + reader.isTampered()); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("HelloWorldStampedMetadata.pdf")); System.out.println("Tampered? " + reader.isTampered()); HashMap<String, String> info = reader.getInfo(); info.put("Subject", "Hello World"); info.put("Author", "your name"); info.put("Keywords", "iText pdf"); info.put("Title", "Hello World stamped"); info.put("Creator", "your name"); stamper.setMoreInfo(info); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XmpWriter xmp = new XmpWriter(baos, info); xmp.close(); stamper.setXmpMetadata(baos.toByteArray()); stamper.close(); }