Example usage for java.util Map get

List of usage examples for java.util Map get

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:Main.java

public static void main(String[] args) {
    String[][] countries = { { "United States", "New York" }, { "United Kingdom", "London" },
            { "Netherland", "Amsterdam" }, { "Japan", "Tokyo" }, { "France", "Paris" } };

    Map countryCapitals = ArrayUtils.toMap(countries);

    System.out.println("Capital of Japan is " + countryCapitals.get("Japan"));
    System.out.println("Capital of France is " + countryCapitals.get("France"));
}

From source file:Main.java

public static void main(String[] args) {
    Map<String, Integer> map = new HashMap<String, Integer>();

    map.put("Age", 25);

    int age = map.get("Age");

    Integer newAge = age + 10;//from  w  w  w . j  a  v a  2 s.co m
}

From source file:com.googlecode.flyway.sample.Main.java

/**
 * Runs the sample.//from w ww .ja v a2  s.  c  o m
 *
 * @param args None supported.
 */
public static void main(String[] args) throws Exception {
    Flyway flyway = new Flyway();
    flyway.setDataSource("jdbc:hsqldb:file:db/flyway_sample;shutdown=true", "SA", "");
    flyway.setLocations("db/migration", "com.googlecode.flyway.sample.migration");
    flyway.migrate();

    SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(flyway.getDataSource());
    List<Map<String, Object>> results = jdbcTemplate.queryForList("select name from test_user");
    for (Map<String, Object> result : results) {
        System.out.println("Name: " + result.get("NAME"));
    }
}

From source file:org.flywaydb.sample.Main.java

/**
 * Runs the sample.//  www. j ava2  s  . c o m
 *
 * @param args None supported.
 */
public static void main(String[] args) throws Exception {
    Flyway flyway = new Flyway();
    flyway.setDataSource("jdbc:hsqldb:file:db/flyway_sample;shutdown=true", "SA", "");
    flyway.setLocations("db/migration", "org.flywaydb.sample.migration");
    flyway.setResolvers(new SampleResolver());
    flyway.migrate();

    SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(flyway.getDataSource());
    List<Map<String, Object>> results = jdbcTemplate.queryForList("select name from test_user");
    for (Map<String, Object> result : results) {
        System.out.println("Name: " + result.get("NAME"));
    }
}

From source file:flywayspike.Main.java

/**
 * Runs the sample.//from   w  w w  .j av a  2  s.c  om
 *
 * @param args None supported.
 */
public static void main(String[] args) throws Exception {
    DataSource dataSource = new SimpleDriverDataSource(new org.hsqldb.jdbcDriver(),
            "jdbc:hsqldb:file:db/flyway_sample;shutdown=true", "SA", "");
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations("flywayspike.migration", "abcd");
    flyway.clean();

    System.out.println("Started Migration");
    flyway.migrate();
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    List<Map<String, Object>> results = jdbcTemplate.queryForList("select name from test_user");
    for (Map<String, Object> result : results) {
        System.out.println("Name: " + result.get("NAME"));
    }

    SqlRowSet rowSet = jdbcTemplate.queryForRowSet("select * from schema_version");
    while (rowSet.next()) {
        System.out.print(rowSet.getObject(1));
        System.out.println("  " + rowSet.getObject(2));
    }
}

From source file:Main.java

public static void main(String[] args) {
    String str = "this is a test";
    char[] char_array = str.toCharArray();

    Map<Character, Integer> charCounter = new TreeMap<Character, Integer>();
    for (char i : char_array) {
        charCounter.put(i, charCounter.get(i) == null ? 1 : charCounter.get(i) + 1);
    }/* w ww  .jav a  2s  .com*/
    for (Character key : charCounter.keySet()) {
        System.out.println("occurrence of '" + key + "' is  " + charCounter.get(key));
    }
}

From source file:Main.java

public static void main(String[] args) {
    Map<String, String> oldMap = new HashMap<String, String>();
    oldMap.put("a", "1");
    oldMap.put("A", "2");

    Map<String, String> newMap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    newMap.putAll(oldMap);//from   w w w .  j  av a  2s .c o  m
    String value = newMap.get("a");
    System.out.println(value);
}

From source file:eu.stratosphere.yarn.YarnTaskManagerRunner.java

public static void main(final String[] args) throws IOException {
    Map<String, String> envs = System.getenv();
    final String yarnClientUsername = envs.get(Client.ENV_CLIENT_USERNAME);
    final String localDirs = envs.get(Environment.LOCAL_DIRS.key());

    // configure local directory
    final String[] newArgs = Arrays.copyOf(args, args.length + 2);
    newArgs[newArgs.length - 2] = "-" + TaskManager.ARG_CONF_DIR;
    newArgs[newArgs.length - 1] = localDirs;
    LOG.info("Setting log path " + localDirs);
    LOG.info("YARN daemon runs as '" + UserGroupInformation.getCurrentUser().getShortUserName() + "' setting"
            + " user to execute Stratosphere TaskManager to '" + yarnClientUsername + "'");
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(yarnClientUsername);
    for (Token<? extends TokenIdentifier> toks : UserGroupInformation.getCurrentUser().getTokens()) {
        ugi.addToken(toks);/*  ww w  .ja v  a  2 s.  c  om*/
    }
    ugi.doAs(new PrivilegedAction<Object>() {
        @Override
        public Object run() {
            try {
                TaskManager.main(newArgs);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    });
}

From source file:drpc.BptiEnsembleQuery.java

public static void main(final String[] args) throws IOException, TException, DRPCExecutionException {
    if (args.length < 3) {
        System.err.println("Where are the arguments? args -- DrpcServer DrpcFunctionName folder");
        return;/*from  w ww  .  j a v  a2s  .  com*/
    }

    final DRPCClient client = new DRPCClient(args[0], 3772, 1000000 /*timeout*/);
    final Queue<String> featureFiles = new ArrayDeque<String>();
    SpoutUtils.listFilesForFolder(new File(args[2]), featureFiles);

    Scanner scanner = new Scanner(featureFiles.peek());
    int i = 0;
    while (scanner.hasNextLine() && i++ < 1) {
        List<Map<String, List<Double>>> dict = SpoutUtils.pythonDictToJava(scanner.nextLine());
        for (Map<String, List<Double>> map : dict) {
            final Double[] features = map.get("chi1").toArray(new Double[0]);
            final Double[] moreFeatures = map.get("chi2").toArray(new Double[0]);
            final Double[] both = (Double[]) ArrayUtils.addAll(features, moreFeatures);
            final String parameters = serializeFeatureVector(ArrayUtils.toPrimitive(both));
            Logger.getAnonymousLogger().log(Level.INFO, runQuery(args[1], parameters, client));
        }
    }
    client.close();
}

From source file:DbUtilsUseMapMySQL.java

public static void main(String[] args) {
    Connection conn = null;//  w  w w .java2  s  . c  o m
    String jdbcURL = "jdbc:mysql://localhost/octopus";
    String jdbcDriver = "com.mysql.jdbc.Driver";
    String user = "root";
    String password = "root";

    try {
        DbUtils.loadDriver(jdbcDriver);
        conn = DriverManager.getConnection(jdbcURL, user, password);

        QueryRunner qRunner = new QueryRunner();

        List mapList = (List) qRunner.query(conn, "select id, name from animals_table", new MapListHandler());

        for (int i = 0; i < mapList.size(); i++) {
            Map map = (Map) mapList.get(i);
            System.out.println("id=" + map.get("id"));
            System.out.println("name=" + map.get("name"));
            System.out.println("-----------------");
        }

        System.out.println("DbUtils_UseMap_MySQL: end.");

    } catch (SQLException e) {
        // handle the exception
        e.printStackTrace();
    } finally {
        DbUtils.closeQuietly(conn);
    }
}