List of usage examples for java.util Map put
V put(K key, V value);
From source file:DiameterMap.java
public static void main(String args[]) { String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" }; float diameters[] = { 4800f, 12103.6f, 12756.3f, 6794f, 142984f, 120536f, 51118f, 49532f, 2274f }; Map map = new TreeMap(); for (int i = 0, n = names.length; i < n; i++) { map.put(names[i], new Float(diameters[i])); }//from www. j a va2 s. co m Iterator it = map.keySet().iterator(); Object obj; while (it.hasNext()) { obj = it.next(); System.out.println(obj + ": " + map.get(obj)); } }
From source file:Main.java
public static void main(String[] args) { // create map Map<String, String> map = new HashMap<String, String>(); // populate the map map.put("1", "A"); map.put("2", "B"); map.put("3", "java2s.com"); // create a synchronized map Map<String, String> synmap = Collections.synchronizedMap(map); System.out.println("Synchronized map is :" + synmap); }
From source file:com.akana.demo.freemarker.templatetester.TestJSON.java
public static void main(String[] args) throws Exception { /* You should do this ONLY ONCE in the whole application life-cycle: */ /* Create and adjust the configuration singleton */ Configuration cfg = new Configuration(Configuration.VERSION_2_3_22); cfg.setDirectoryForTemplateLoading(new File("/Users/ian.goldsmith/projects/freemarker")); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); /*/*from www . ja va2s. c o m*/ * You usually do these for MULTIPLE TIMES in the application * life-cycle: */ /* Create a data-model */ Map message = new HashMap(); message.put("contentAsString", FileUtils.readFileToString( new File("/Users/ian.goldsmith/projects/freemarker/test.json"), StandardCharsets.UTF_8)); Map root = new HashMap(); root.put("message", message); /* Get the template (uses cache internally) */ Template temp = cfg.getTemplate("testjson.ftl"); /* Merge data-model with template */ Writer out = new OutputStreamWriter(System.out); temp.process(root, out); // Note: Depending on what `out` is, you may need to call `out.close()`. // This is usually the case for file output, but not for servlet output. }
From source file:com.akana.demo.freemarker.templatetester.TestXML.java
public static void main(String[] args) throws Exception { /* You should do this ONLY ONCE in the whole application life-cycle: */ /* Create and adjust the configuration singleton */ Configuration cfg = new Configuration(Configuration.VERSION_2_3_22); cfg.setDirectoryForTemplateLoading(new File("/Users/ian.goldsmith/projects/freemarker")); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); /*/*from w w w . jav a2 s .c o m*/ * You usually do these for MULTIPLE TIMES in the application * life-cycle: */ /* Create a data-model */ Map message = new HashMap(); message.put("contentAsXml", freemarker.ext.dom.NodeModel.parse(new File("/Users/ian.goldsmith/projects/freemarker/test.xml"))); Map root = new HashMap(); root.put("message", message); /* Get the template (uses cache internally) */ Template temp = cfg.getTemplate("testxml.ftl"); /* Merge data-model with template */ Writer out = new OutputStreamWriter(System.out); temp.process(root, out); // Note: Depending on what `out` is, you may need to call `out.close()`. // This is usually the case for file output, but not for servlet output. }
From source file:cz.hobrasoft.pdfmu.jackson.SchemaGenerator.java
public static void main(String[] args) throws JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); // nice formatting SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); Map<String, Type> types = new HashMap<>(); types.put("RpcResponse", RpcResponse.class); types.put("result/inspect", Inspect.class); types.put("result/version set", VersionSet.class); types.put("result/signature add", SignatureAdd.class); types.put("result/empty", EmptyResult.class); for (Map.Entry<String, Type> e : types.entrySet()) { String name = e.getKey(); String filename = String.format("schema/%s.json", name); Type type = e.getValue(); mapper.acceptJsonFormatVisitor(mapper.constructType(type), visitor); JsonSchema jsonSchema = visitor.finalSchema(); mapper.writeValue(new File(filename), jsonSchema); }/*w w w .jav a 2 s .c o m*/ }
From source file:HashMapExample.java
public static void main(String[] args) { Map<Integer, String> map = new HashMap<Integer, String>(); map.put(new Integer(1), "One"); map.put(new Integer(2), "Two"); map.put(new Integer(3), "Three"); map.put(new Integer(4), "Four"); map.put(new Integer(5), "Five"); System.out.println("Map Values Before: "); Set keys = map.keySet();//from ww w .ja v a 2 s . co m for (Iterator i = keys.iterator(); i.hasNext();) { Integer key = (Integer) i.next(); String value = (String) map.get(key); System.out.println(key + " = " + value); } System.out.println("\nRemove element with key 6"); map.remove(new Integer(6)); System.out.println("\nMap Values After: "); keys = map.keySet(); for (Iterator i = keys.iterator(); i.hasNext();) { Integer key = (Integer) i.next(); String value = (String) map.get(key); System.out.println(key + " = " + value); } }
From source file:MyComparator.java
public static void main(String[] args) { Map<String, Integer> unsortMap = new HashMap<String, Integer>(); unsortMap.put("B", 5); unsortMap.put("A", 8); unsortMap.put("D", 2); unsortMap.put("C", 7); System.out.println("Before sorting......"); System.out.println(unsortMap); Map<String, Integer> sortedMapAsc = Util.sortByComparator(unsortMap); System.out.println(sortedMapAsc); }
From source file:com.apress.prospringintegration.jmx.JmxOperationGateway.java
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmx/operation-gateway.xml"); Map<String, Integer> parameters = new HashMap<String, Integer>(); parameters.put("p1", 5); parameters.put("p2", 7); MessageChannel request = (MessageChannel) context.getBean("request"); request.send(MessageBuilder.withPayload(parameters).build()); try {// w w w .j av a2s. co m Thread.sleep(180000); } catch (InterruptedException e) { //do nothing } context.stop(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Map weakMap = new WeakHashMap(); Object keyObject = ""; Object valueObject = ""; weakMap.put(keyObject, valueObject); Iterator it = weakMap.keySet().iterator(); while (it.hasNext()) { Object key = it.next();/*from www .j a v a 2s.c o m*/ } }
From source file:com.apress.prospringintegration.jdbc.JdbcOutbound.java
public static void main(String[] args) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("/spring/jdbc/jdbc-outbound-context.xml"); MessageChannel input = context.getBean("input", MessageChannel.class); Map<String, Object> rowMessage = new HashMap<String, Object>(); rowMessage.put("id", 3); rowMessage.put("firstname", "Mr"); rowMessage.put("lastname", "Bill"); rowMessage.put("status", 0); Message<Map<String, Object>> message = MessageBuilder.withPayload(rowMessage).build(); input.send(message);// w ww . j a v a2s. co m }