Example usage for java.util Map keySet

List of usage examples for java.util Map keySet

Introduction

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

Prototype

Set<K> keySet();

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:com.doculibre.constellio.utils.SolrSchemaUtils.java

public static void main(String[] args) throws Exception {
    ConnectorType connectorType = new ConnectorType();
    connectorType.setName("mail");
    IndexSchema schema = getSchema(connectorType);
    Map<String, FieldType> fieldTypes = schema.getFieldTypes();
    for (String key : fieldTypes.keySet()) {
        FieldType fieldType = fieldTypes.get(key);
        System.out.print(key + ":");
        System.out.print(fieldType.getClass());
        System.out.print("\n");
        System.out.print(fieldType.getAnalyzer().getClass());
    }//from w  ww.ja  v a2 s .  c om
}

From source file:Main.java

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

    map.put("Adobe", "Mountain View, CA");
    map.put("IBM", "White Plains, NY");
    map.put("Learning Tree", "Los Angeles, CA");

    Iterator k = map.keySet().iterator();
    while (k.hasNext()) {
        String key = (String) k.next();
        System.out.println("Key " + key + "; Value " + (String) map.get(key));
    }//from   w  w  w  .  jav a2  s .  c  o  m
}

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]);//w ww  . j  a  va  2  s .c  om
    }

    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 .j  a va  2s. co  m*/
 */
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:br.com.recursive.biblioteca.servicos.EmailService.java

public static void main(String[] args) throws EmailException {

    //        Pessoa p = new Pessoa();
    //        p.setNome("sdsfsdf");
    //        //from  ww  w .  j  a v a2 s. c  o  m
    //        Contato c = new Contato();
    //        c.setEmail("oelisiany@gmail.com");
    //        
    //        p.setContato(c);
    //        p.setUsuario(new Usuario());
    //        
    //        EmailService es = new EmailService();
    //        es.sendHtmlEmail(p);

    Map<String, Object> map1 = new HashMap<String, Object>();
    map1.put("cpf", "312313123");
    map1.put("id", 1);

    for (String chave : map1.keySet()) {
        System.out.println(chave);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Map<String, String> map = new LinkedHashMap<String, String>();

    map.put("1", "value1");
    map.put("2", "value2");
    map.put("3", "value3");
    map.put("2", "value4");

    for (Iterator it = map.keySet().iterator(); it.hasNext();) {
        Object key = it.next();// w ww.j a v a2  s.c  o m
        Object value = map.get(key);
    }
}

From source file:com.blockhaus2000.csvviewer.CsvViewerMain.java

public static void main(final String[] args) {
    try (final CSVParser parser = new CSVParser(new InputStreamReader(System.in), CSVFormat.DEFAULT)) {
        final Table table = new Table();

        final Map<String, Integer> headerMap = parser.getHeaderMap();
        if (headerMap != null) {
            final TableRow headerRow = new TableRow();
            headerMap.keySet().forEach(headerData -> headerRow.addCell(new TableRowCell(headerData)));
            table.setHeaderRow(headerRow);
        }/* w  ww.  j  a  v a  2s  .  c o m*/

        final AtomicBoolean asHeader = new AtomicBoolean(headerMap == null);
        parser.getRecords().forEach(record -> {
            final TableRow row = new TableRow();
            record.forEach(rowData -> row.addCell(new TableRowCell(rowData)));
            if (asHeader.getAndSet(false)) {
                table.setHeaderRow(row);
            } else {
                table.addRow(row);
            }
        });

        System.out.println(table.getFormattedString());
    } catch (final IOException cause) {
        throw new RuntimeException("An error occurred whilst parsing stdin!", cause);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object keyObject = "";
    Object valueObject = "";
    Map weakMap = new WeakHashMap();

    weakMap.put(keyObject, valueObject);
    WeakReference weakValue = new WeakReference(valueObject);

    weakMap.put(keyObject, weakValue);/*from   ww w .  j ava2s .co m*/

    Iterator it = weakMap.keySet().iterator();
    while (it.hasNext()) {
        Object key = it.next();
        weakValue = (WeakReference) weakMap.get(key);
        if (weakValue == null) {
            System.out.println("Value has been garbage-collected");
        } else {
            System.out.println("Get value");
            valueObject = weakValue.get();
        }
    }
}

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);
    }//from ww w  .  j  a v a 2 s  .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, int[]> map = new TreeMap<String, int[]>();

    int[] array = new int[3];
    array[0] = 0;/*from   w ww . j  av a 2s . 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]);
        }
    }
}