List of usage examples for java.util Map put
V put(K key, V value);
From source file:ArrayMap.java
public static void main(String args[]) { Map map = new ArrayMap(13); map.put("1", "One"); map.put("2", "Two"); map.put("3", "Three"); map.put("4", "Four"); map.put("5", "Five"); map.put("6", "Six"); map.put("7", "Seven"); map.put("8", "Eight"); map.put("9", "Nine"); map.put("10", "Ten"); map.put("11", "Eleven"); map.put("12", "Twelve"); map.put("13", "Thirteen"); System.out.println(map);//from w w w.ja v a2 s. c o m System.out.println(map.keySet()); System.out.println(map.values()); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { ProcessBuilder launcher = new ProcessBuilder(); Map<String, String> environment = launcher.environment(); launcher.redirectErrorStream(true);/*from ww w .ja v a2s.c om*/ launcher.directory(new File("c:\\")); environment.put("name", "var"); launcher.command("notepad.exe"); Process p = launcher.start(); // And launch a new process BufferedReader output = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = output.readLine()) != null) System.out.println(line); // The process should be done now, but wait to be sure. p.waitFor(); }
From source file:Main.java
public static void main(String[] args) { List<String> aList = new ArrayList<String>(); Map<Integer, String> aMap = new HashMap<Integer, String>(); aList.add("A"); aList.add("B"); for (int i = 0; i < aList.size(); i++) { aMap.put(i + 1, aList.get(i)); }//from w w w .jav a 2s .c o m System.out.println(aMap.toString()); }
From source file:Main.java
public static void main(String[] args) { String yourString = "UNDERSTAND"; Map<Character, Integer> count = new TreeMap<Character, Integer>(); for (char c : yourString.toCharArray()) { if (count.containsKey(c)) { count.put(c, (int) count.get(c) + 1); } else {/*from www .j a va 2s .c o m*/ count.put(c, 1); } } System.out.println(count); }
From source file:com.facebook.infrastructure.net.io.TcpReader.java
public static void main(String[] args) throws Throwable { Map<TcpReaderState, StartState> stateMap = new HashMap<TcpReaderState, StartState>(); stateMap.put(TcpReaderState.CONTENT, new ContentState(null, 10)); stateMap.put(TcpReaderState.START, new ProtocolState(null)); stateMap.put(TcpReaderState.CONTENT_LENGTH, new ContentLengthState(null)); StartState state = stateMap.get(TcpReaderState.CONTENT); System.out.println(state.getClass().getName()); state = stateMap.get(TcpReaderState.CONTENT_LENGTH); System.out.println(state.getClass().getName()); }
From source file:example.client.CamelMongoJmsStockClient.java
@SuppressWarnings("resource") public static void main(final String[] args) throws Exception { systemProps = loadProperties();//w w w. j a v a2 s .com AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml"); ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class); List<Map<String, Object>> stocks = readJsonsFromMongoDB(); for (Map<String, Object> stock : stocks) { stock.remove("_id"); stock.remove("Earnings Date"); camelTemplate.sendBody(String.format("jms:queue:%s", systemProps.getProperty("ticker.queue.name")), ExchangePattern.InOnly, stock); } new Timer().schedule(new TimerTask() { @Override public void run() { Map<String, Object> aRandomStock = stocks.get(RandomUtils.nextInt(0, stocks.size())); aRandomStock.put("Price", ((Double) aRandomStock.get("Price")) + RandomUtils.nextFloat(0.1f, 9.99f)); camelTemplate.sendBody(String.format("jms:queue:%s", systemProps.getProperty("ticker.queue.name")), ExchangePattern.InOnly, aRandomStock); } }, 1000, 2000); }
From source file:burstcoin.observer.Observer.java
public static void main(String[] args) throws Exception { LOG.info("Starting the engines ... please wait!"); // overwritten by application.properties Map<String, Object> properties = new HashMap<String, Object>(); properties.put("server.port", ObserverProperties.getObserverPort()); properties.put("spring.mail.protocol", ObserverProperties.getMailProtocol()); properties.put("spring.mail.host", ObserverProperties.getMailHost()); properties.put("spring.mail.port", ObserverProperties.getMailPort()); properties.put("spring.mail.username", ObserverProperties.getMailUsername()); properties.put("spring.mail.password", ObserverProperties.getMailPassword()); properties.put("spring.thymeleaf.cache", ObserverProperties.isEnableTemplateCaching()); new SpringApplicationBuilder(Observer.class).properties(properties).build(args).run(); }
From source file:Main.java
public static void main(String[] args) { Map<String, int[]> map = new TreeMap<String, int[]>(); int[] array = new int[3]; array[0] = 0;//from w w w . ja v a2 s .c o m array[1] = 1; array[2] = 2; map.put("array", array); Iterator<String> iter = map.keySet().iterator(); while (iter.hasNext()) { String arrayName = iter.next(); array = map.get(arrayName); System.out.print(arrayName + ":"); for (int i = 0; i < array.length; i++) { System.out.print(array[i]); } } }
From source file:com.npower.dm.util.ConvertMailProfile.java
/** * @param args/*ww w .j a va 2 s .co m*/ */ public static void main(String[] args) throws Exception { File outputFile = new File("c:/temp/mail.xml"); FileWriter writer = new FileWriter(outputFile); File csvFile = new File("c:/temp/mail.csv"); BufferedReader reader = new BufferedReader(new FileReader(csvFile)); String line = reader.readLine(); while (line != null) { line = reader.readLine(); if (StringUtils.isEmpty(line)) { continue; } String[] cols = StringUtils.split(line, ','); Map<String, String> values = new HashMap<String, String>(); values.put("name", cols[0]); values.put("smtp.host", cols[1]); values.put("pop.host", cols[2]); writeXML(writer, values); } writer.close(); reader.close(); }
From source file:TypeMapDemo.java
public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException { Properties p = new Properties(); p.load(new FileInputStream("db.properties")); Class c = Class.forName(p.getProperty("db.driver")); System.out.println("Loaded driverClass " + c.getName()); Connection con = DriverManager.getConnection(p.getProperty("db.url"), "student", "student"); System.out.println("Got Connection " + con); Statement s = con.createStatement(); int ret;/*from ww w . ja v a 2 s . com*/ try { s.executeUpdate("drop table MR"); s.executeUpdate("drop type MUSICRECORDING"); } catch (SQLException andDoNothingWithIt) { // Should use "if defined" but not sure it works for UDTs... } ret = s.executeUpdate("create type MUSICRECORDING as object (" + " id integer," + " title varchar(20), " + " artist varchar(20) " + ")"); System.out.println("Created TYPE! Ret=" + ret); ret = s.executeUpdate("create table MR of MUSICRECORDING"); System.out.println("Created TABLE! Ret=" + ret); int nRows = s.executeUpdate("insert into MR values(123, 'Greatest Hits', 'Ian')"); System.out.println("inserted " + nRows + " rows"); // Put the data class into the connection's Type Map // If the data class were not an inner class, // this would likely be done with Class.forName(...); Map map = con.getTypeMap(); map.put("MUSICRECORDING", MusicRecording.class); con.setTypeMap(map); ResultSet rs = s.executeQuery("select * from MR where id = 123"); //"select musicrecording(id,artist,title) from mr"); rs.next(); for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { Object o = rs.getObject(i); System.out.print(o + "(Type " + o.getClass().getName() + ")\t"); } System.out.println(); }