List of usage examples for java.util Map put
V put(K key, V value);
From source file:Main.java
public static void main(String[] a) { Map<String, String> yourMap = new HashMap<String, String>(); yourMap.put("1", "one"); yourMap.put("2", "two"); yourMap.put("3", "three"); Map<String, Object> map = new LinkedHashMap<String, Object>(); List<String> keyList = new ArrayList<String>(yourMap.keySet()); List<String> valueList = new ArrayList<String>(yourMap.values()); Set<String> sortedSet = new TreeSet<String>(valueList); Object[] sortedArray = sortedSet.toArray(); int size = sortedArray.length; for (int i = 0; i < size; i++) { map.put(keyList.get(valueList.indexOf(sortedArray[i])), sortedArray[i]); }/* ww w . j a v a 2 s .c o m*/ Set ref = map.keySet(); Iterator it = ref.iterator(); while (it.hasNext()) { String i = (String) it.next(); System.out.println(i); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Map map = new HashMap(); map = Collections.unmodifiableMap(map); try {//from w w w . j a v a2 s . com map.put("key", "new value"); } catch (UnsupportedOperationException e) { System.out.println(e.getMessage()); } }
From source file:Main.java
public static void main(String[] args) { Map<String, Integer> map = new HashMap<String, Integer>(); // add some values in the map map.put("One", 1); map.put("Two", 2); map.put("Three", 3); LinkedHashMap<String, Integer> linkMap = new LinkedHashMap<String, Integer>(map); System.out.println(linkMap);/*w w w .j a v a 2 s . c o m*/ }
From source file:Main.java
License:asdf
public static void main(String[] args) { Map<String, String> map = new HashMap<String, String>(); map.put("KeyA", "erty"); map.put("KeyC", "trwe"); map.put("KeyD", "wert"); map.put("KeyB", "fdsd"); map.put("KeyS", "dsa"); map.put("KeyE", "fdas"); map.put("KeyG", "asdf"); System.out.println(sort(map, new Comparator<String>() { @Override/*from w w w . j a v a 2 s. c o m*/ public int compare(String o1, String o2) { return o1.compareTo(o2); } })); }
From source file:com.apress.prospringintegration.transform.Transformer.java
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:transformer.xml"); MessageChannel input = context.getBean("input", MessageChannel.class); PollableChannel output = context.getBean("output", PollableChannel.class); Map<String, String> customerMap = new HashMap<String, String>(); customerMap.put("firstName", "John"); customerMap.put("lastName", "Smith"); customerMap.put("address", "100 State Street"); customerMap.put("city", "Los Angeles"); customerMap.put("state", "CA"); customerMap.put("zip", "90064"); Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build(); input.send(message);// ww w. ja va2s . c o m Message<?> reply = output.receive(); System.out.println("received: " + reply.getPayload()); }
From source file:Employee.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@myserver:1521:ORCL", "yourName", "mypwd"); Statement stmt = conn.createStatement(); Map map = conn.getTypeMap(); map.put("EMP_DATA", Class.forName("Employee")); conn.setTypeMap(map);//from w ww. j av a2s.c o m ResultSet rs = stmt.executeQuery("SELECT * from Emp"); Employee employee; while (rs.next()) { int empId = rs.getInt("EmpId"); employee = (Employee) rs.getObject("Emp_Info"); System.out.print("Employee Id: " + empId + ", SSN: " + employee.SSN); System.out.print(", Name: " + employee.FirstName + " " + employee.LastName); System.out.println( ", Yearly Salary: $" + employee.Salary + " Monthly Salary: " + employee.calcMonthlySalary()); } conn.close(); }
From source file:com.apress.prospringintegration.transform.HeaderEnricher.java
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "classpath:header-enricher.xml"); MessageChannel input = context.getBean("input", MessageChannel.class); PollableChannel output = context.getBean("output", PollableChannel.class); Map<String, String> customerMap = new HashMap<String, String>(); customerMap.put("firstName", "John"); customerMap.put("lastName", "Smith"); customerMap.put("address", "100 State Street"); customerMap.put("city", "Los Angeles"); customerMap.put("state", "CA"); customerMap.put("zip", "90064"); Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build(); input.send(message);//from www.j a va2 s . co m Message<?> reply = output.receive(); System.out.println("received: " + reply); }
From source file:com.apress.prospringintegration.transform.PayloadTypeTransformer.java
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "classpath:payload-type-transformer.xml"); MessageChannel input = context.getBean("input", MessageChannel.class); PollableChannel output = context.getBean("output", PollableChannel.class); Map<String, String> customerMap = new HashMap<String, String>(); customerMap.put("firstName", "John"); customerMap.put("lastName", "Smith"); customerMap.put("address", "100 State Street"); customerMap.put("city", "Los Angeles"); customerMap.put("state", "CA"); customerMap.put("zip", "90064"); Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build(); input.send(message);/* w ww . j av a2 s . co m*/ Message<?> reply = output.receive(); System.out.println("received: " + reply.getPayload()); }
From source file:com.apress.prospringintegration.transform.ProgrammaticHeaderEnricher.java
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "classpath:programmatic-header-enricher.xml"); MessageChannel input = context.getBean("input", MessageChannel.class); PollableChannel output = context.getBean("output", PollableChannel.class); Map<String, String> customerMap = new HashMap<String, String>(); customerMap.put("firstName", "John"); customerMap.put("lastName", "Smith"); customerMap.put("address", "100 State Street"); customerMap.put("city", "Los Angeles"); customerMap.put("state", "CA"); customerMap.put("zip", "90064"); Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build(); input.send(message);//from w w w. ja v a2s. c o m Message<?> reply = output.receive(); System.out.println("received: " + reply); }
From source file:com.apress.prospringintegration.wiretap.WireTapExample.java
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "classpath:wiretap/wiretap.xml"); MessageChannel input = context.getBean("input", MessageChannel.class); PollableChannel output = context.getBean("output", PollableChannel.class); Map<String, String> customerMap = new HashMap<String, String>(); customerMap.put("firstName", "John"); customerMap.put("lastName", "Smith"); customerMap.put("address", "100 State Street"); customerMap.put("city", "Los Angeles"); customerMap.put("state", "CA"); customerMap.put("zip", "90064"); Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build(); input.send(message);//from www.jav a2 s. c o m Message<?> reply = output.receive(); System.out.println("received: " + reply.getPayload()); }