Example usage for java.util Map put

List of usage examples for java.util Map put

Introduction

In this page you can find the example usage for java.util Map put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:Main.java

public static void main(String[] args) {
    String text = "A,B,C,D";

    String[] keyValue = text.split(",");

    Map<Integer, String> myMap = new HashMap<Integer, String>();
    for (int i = 0; i < keyValue.length; i++) {
        myMap.put(i, keyValue[i]);
    }//www .j  av a  2 s. c  o m

    Set keys = myMap.keySet();
    Iterator itr = keys.iterator();

    while (itr.hasNext()) {
        Integer key = (Integer) itr.next();
        String value = (String) myMap.get(key);
        System.out.println(key + " - " + value);
    }
}

From source file:com.github.fastjson.MapPractice.java

/**
 * @param args//from   w w  w . ja  va  2  s  .  com
 */
public static void main(String[] args) {
    Map<String, String> map = new HashMap<>();
    map.put("name", "doctor");
    map.put("age", "1118");
    map.put("sex", "man");
    String jsonString = JSON.toJSONString(map);
    System.out.println(jsonString);

    InputStream resourceAsStream = MapPractice.class.getResourceAsStream("/fastjson/map1.json");
    String jString = null;
    try {
        jString = IOUtils.toString(resourceAsStream);

    } catch (IOException e) {
        e.printStackTrace();
    }

    Map<?, ?> parse = JSON.parseObject(jString, Map.class);
    System.out.println(parse);
    for (Object key : parse.keySet()) {
        System.out.println(key + ":" + parse.get(key));
    }

    InputStream resourceAsStream2 = MapPractice.class.getResourceAsStream("/fastjson/map2.json");
    String jString2 = null;
    try {
        jString2 = IOUtils.toString(resourceAsStream2);
    } catch (IOException e) {
        e.printStackTrace();
    }
    Map<?, ?> parseObject = JSON.parseObject(jString2, Map.class);
    System.out.println(JSON.toJSON(parseObject));

    System.out.println("??");

    Object object = parseObject.get("currentKey");
    System.out.println("currentKey" + ":" + object);
    Map<?, ?> object2 = (Map<?, ?>) parseObject.get("keyMap");
    for (Object key : object2.keySet()) {
        System.out.println(key + ":" + object2.get(key));
    }
}

From source file:Main.java

public static void main(String args[]) {
    MyObject c1 = new MyObject(1, "one");
    MyObject c2 = new MyObject(2, "two");
    MyObject c3 = new MyObject(3, "three");

    MyObject c4 = new MyObject(1, "one");
    MyObject c5 = new MyObject(2, "two");
    MyObject c6 = new MyObject(3, "three");

    Map<Integer, MyObject> map = new HashMap<Integer, MyObject>();
    map.put(c1.getId(), c1);
    map.put(c2.getId(), c2);/* w  w w  .  ja  v  a 2s  .c  om*/
    map.put(c3.getId(), c3);
    map.put(c4.getId(), c4);
    map.put(c5.getId(), c5);
    map.put(c6.getId(), c6);

    System.out.println(map);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Map map = new HashMap();

    // Create int wrapper object
    Integer refInt = new Integer(123);

    // Store int in map
    map.put("key", refInt);

    // Get int value from map
    refInt = (Integer) map.get("key");

    // Get the integer value from wrapper object
    int i = refInt.intValue();
}

From source file:org.apache.streams.elasticsearch.example.ElasticsearchDelete.java

public static void main(String[] args) {
    LOGGER.info(StreamsConfigurator.config.toString());

    Config reindex = StreamsConfigurator.config.getConfig("reindex");

    Config source = reindex.getConfig("source");
    Config destination = reindex.getConfig("destination");

    ElasticsearchReaderConfiguration elasticsearchSourceConfiguration = ElasticsearchConfigurator
            .detectReaderConfiguration(source);

    ElasticsearchPersistReader elasticsearchPersistReader = new ElasticsearchPersistReader(
            elasticsearchSourceConfiguration);

    ElasticsearchWriterConfiguration elasticsearchDestinationConfiguration = ElasticsearchConfigurator
            .detectWriterConfiguration(destination);

    ElasticsearchPersistWriter elasticsearchPersistWriter = new ElasticsearchPersistDeleter(
            elasticsearchDestinationConfiguration);

    Map<String, Object> streamConfig = Maps.newHashMap();
    streamConfig.put(LocalStreamBuilder.TIMEOUT_KEY, 20 * 60 * 1000);
    StreamBuilder builder = new LocalStreamBuilder(1000, streamConfig);

    builder.newPerpetualStream(ElasticsearchPersistReader.STREAMS_ID, elasticsearchPersistReader);
    builder.addStreamsPersistWriter(ElasticsearchPersistWriter.STREAMS_ID, elasticsearchPersistWriter, 1,
            ElasticsearchPersistReader.STREAMS_ID);
    builder.start();//  w  ww  . ja  va2 s.  com

}

From source file:org.apache.streams.elasticsearch.example.ElasticsearchReindex.java

public static void main(String[] args) {
    LOGGER.info(StreamsConfigurator.config.toString());

    Config reindex = StreamsConfigurator.config.getConfig("reindex");

    Config source = reindex.getConfig("source");
    Config destination = reindex.getConfig("destination");

    ElasticsearchReaderConfiguration elasticsearchSourceConfiguration = ElasticsearchConfigurator
            .detectReaderConfiguration(source);

    ElasticsearchPersistReader elasticsearchPersistReader = new ElasticsearchPersistReader(
            elasticsearchSourceConfiguration);

    ElasticsearchWriterConfiguration elasticsearchDestinationConfiguration = ElasticsearchConfigurator
            .detectWriterConfiguration(destination);

    ElasticsearchPersistWriter elasticsearchPersistWriter = new ElasticsearchPersistWriter(
            elasticsearchDestinationConfiguration);

    Map<String, Object> streamConfig = Maps.newHashMap();
    streamConfig.put(LocalStreamBuilder.TIMEOUT_KEY, 20 * 60 * 1000);
    StreamBuilder builder = new LocalStreamBuilder(1000, streamConfig);

    builder.newPerpetualStream(ElasticsearchPersistReader.STREAMS_ID, elasticsearchPersistReader);
    builder.addStreamsPersistWriter(ElasticsearchPersistWriter.STREAMS_ID, elasticsearchPersistWriter, 1,
            ElasticsearchPersistReader.STREAMS_ID);
    builder.start();/*  w  ww.java  2 s  . co  m*/

}

From source file:com.dianping.maven.plugin.tools.misc.file.ServiceLionPropertiesGenerator.java

public static void main(String[] args) throws Exception {
    ServiceLionPropertiesGenerator serviceLionPropertiesGenerator = new ServiceLionPropertiesGenerator();

    Map<String, File> projectBaseDirMapping = new HashMap<String, File>();
    projectBaseDirMapping.put("alpaca", new File("/Volumes/HDD/dev_env_work/war/alpaca.war"));
    ProjectMetaContext projectMetaContext = new ProjectMetaContext("com.mysql.jdbc.Driver",
            "jdbc:mysql://192.168.7.105:3306/hawk", "dpcom_hawk", "123456");
    serviceLionPropertiesGenerator.generate(new ServiceLionContext(projectBaseDirMapping, projectMetaContext,
            "127.0.0.1", new File("/Users/leoleung/phoenix-test"), true));
}

From source file:license.mac.MacTest.java

public static void main(String[] args) throws Exception {
    Map<Integer, String> infoMap = new HashMap<Integer, String>();
    infoMap.put(1, "");
    infoMap.put(2, "");
    infoMap.put(2, "");
    infoMap.put(2, "");
    infoMap.put(12, "eth0");

    MacTest mac = new MacTest();

    System.out.println();/*from   ww w . ja v  a  2 s  .c om*/
    System.out.println();
    System.out.println("************?mac?*********");
    System.out.println();
    System.out.println();
    InetAddress ia = InetAddress.getLocalHost();//?IP
    System.out.println("IP .........: " + ia.getHostAddress());
    System.out.println("MAC .........: " + getMACAddress(ia));

    System.out.println();
    System.out.println();
    mac.checkMac();
}

From source file:burstcoin.jminer.JMinerApplication.java

public static void main(String[] args) {
    LOG.info("Starting the engines ... please wait!");

    // overwritten by application.properties
    Map<String, Object> properties = new HashMap<>();
    if (CoreProperties.isWriteLogFile()) {
        properties.put("logging.file", CoreProperties.getLogFilePath());
    }//from w w w .  j ava  2s . com
    properties.put("logging.level.burstcoin.jminer.core", CoreProperties.isDebug() ? "DEBUG" : "INFO");

    new SpringApplicationBuilder(JMinerApplication.class).bannerMode(Banner.Mode.OFF) // turn off spring boot banner
            .logStartupInfo(false).properties(properties) // add application.properties
            .build(args).run();
}

From source file:com.sm.store.TestHessianPhp.java

public static void main(String[] args) throws Exception {
    HessianSerializer hs = new HessianSerializer();
    //        Map<String, String> map = new HashMap<String, String>();
    //        map.put("Header", "com.sm.message.Header");
    //        map.put("StoreParas", "com.sm.store.StoreParas");
    //        map.put("Value","com.sm.store.Value");
    //        map.put("array", "java.util.HashMap");
    HessianPhp hessianPhp = new HessianPhp(getNameMap());
    Map<String, Header> mapH = new HashMap<String, Header>();
    mapH.put("key-1", new Header("test-1", 1, (byte) 2, 3));
    mapH.put("key-2", new Header("test-2", 2, (byte) 3, 4));
    //        byte[] m1 = hs.toBytes( mapH);
    //        System.out.println("m1 "+m1.length);
    //        Header hd = new Header("test-1", 2, (byte)1, 3);
    //        byte[] d2 = hs.toBytes( hd);
    //        HessianReader reader = new HessianReader( m1);
    //        reader.readObject();
    //        System.out.println(new String( reader.getBytes()));
    List list = new ArrayList();
    list.add(new Header("test-1", 1, (byte) 2, 3));
    list.add(new Header("test-2", 2, (byte) 3, 4));
    byte[] d3 = hs.toBytes(list);
    HessianReader reader = new HessianReader(d3);
    reader.readObject();/*w  w w  .  j  a  v  a  2  s.  c  o  m*/
    System.out.println(new String(reader.getBytes()));
    //        byte[] data = hessianPhp.php2Hessian( header.getBytes());
    //        Header header = new Header("test-1",10, (byte) 3,1 );
    //        byte[] d1 = hs.toBytes( header);
    //logger.info("len "+data.length+" "+d1.length);
    //Object obj = hs.toObject(data);
    //logger.info(obj.getClass().getName()+" obj "+obj.toString());
    //        byte[] s1 = hessianPhp.php2Hessian( storePara.getBytes());
    //        Object obj = hs.toObject( s1);
    //        logger.info(obj.toString());

}