Example usage for java.util Map entrySet

List of usage examples for java.util Map entrySet

Introduction

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

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] args) {

    HashMap<String, Integer> map = new HashMap<String, Integer>();

    map.put("item1", 1);
    map.put("item2", 2);
    map.put("item3", 1);
    map.put("item4", 7);
    map.put("item5", 3);
    map.put("item6", 4);

    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        System.out.println("Item is:" + entry.getKey() + " with value:" + entry.getValue());
    }/*from   w  ww  .ja v  a 2 s . com*/

    Map<String, Integer> sortedMap = sortByValue(map);

    for (Map.Entry<String, Integer> entry : sortedMap.entrySet()) {
        System.out.println("Item is:" + entry.getKey() + " with value:" + entry.getValue());
    }
}

From source file:de.britter.beyondstringutils.BeanUtils2Example.java

public static void main(String[] args) {
    Person person = new Person("John", "Doe", "19.03.1970");

    on(person).set("firstName").with("William");

    Map<String, Object> props = on(person).describe();
    for (Map.Entry<String, Object> prop : props.entrySet()) {
        System.out.println(prop.getKey() + ": " + prop.getValue());
    }/*from  www.  j av  a 2  s .  c  o m*/
}

From source file:MainClass.java

public static void main(String[] a) {

    Map map = new HashMap();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");
    Set set = map.entrySet();

    Iterator iter = set.iterator();

    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        System.out.println(entry.getKey() + " -- " + entry.getValue());
    }//from www  . ja  v a2s  . c om
}

From source file:Main.java

public static final void main(String[] args) {
    Map<String, String> m = new HashMap<>();
    m.put("a", "alpha");
    m.put("b", "beta");

    Iterator<Map.Entry<String, String>> it = m.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, String> entry = it.next();
        if (entry.getKey() == "b") {
            entry.setValue("new Value");
        }//from www .j  a v a2s.co m
    }
    it = m.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, String> entry = it.next();
        System.out.println("key = " + entry.getKey() + ", value = " + entry.getValue());
    }
}

From source file:jp.ac.titech.cs.se.sparesort.Main.java

public static void main(String[] args) throws Exception {
    SequenceDatabase<String> sdb = new SequenceDatabase<String>();

    int minSup = Integer.parseInt(args[0]);
    for (int i = 1; i < args.length; i++) {
        sdb.addSequence(loadStringListFromFile(args[i]));
    }//from  w w  w .  j a v  a 2s .  co m

    Map<List<String>, Integer> result = sdb.mineFrequentClosedSequences(minSup);
    for (Map.Entry<List<String>, Integer> entry : result.entrySet()) {
        System.out.println(entry.getKey() + ":" + entry.getValue());
    }
}

From source file:se.uu.it.cs.recsys.ruleminer.FPGrowthApp.java

public static void main(String[] args) {
    try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
            CourseRecommenderRuleMinerSpringConfig.class)) {

        FPGrowthApp app = ctx.getBean(FPGrowthApp.class);

        int minSupport = FPGrowthImpl.DEFAULT_MIN_SUPPORT;
        FPTree tree = app.treeBuilder.buildTreeFromDB(minSupport);

        if (tree == null) {
            LOGGER.debug("No FP tree can be built to meet the min support {} ", minSupport);
            return;
        }//from   w w w  .ja  v  a2s . c  o  m

        Map<Set<Integer>, Integer> patterns = app.ruleMiner.getAllFrequentPattern(tree, minSupport);

        patterns.entrySet().stream().filter(entry -> entry.getKey().size() > 1).forEach(entry -> {
            LOGGER.info("#### Pattern: {}, support: {}", entry.getKey(), entry.getValue());
        });

    }
}

From source file:MainClass.java

public static void main(String[] args) {
    try {/*from w w  w .  j av a 2s  .c  o m*/

        URL url = new URL("http://www.java2s.com/");
        URLConnection urlConnection = url.openConnection();
        Map<String, List<String>> headers = urlConnection.getHeaderFields();
        Set<Map.Entry<String, List<String>>> entrySet = headers.entrySet();
        for (Map.Entry<String, List<String>> entry : entrySet) {
            String headerName = entry.getKey();
            System.out.println("Header Name:" + headerName);
            List<String> headerValues = entry.getValue();
            for (String value : headerValues) {
                System.out.print("Header value:" + value);
            }
            System.out.println();
            System.out.println();
        }
        InputStream inputStream = urlConnection.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String line = bufferedReader.readLine();
        while (line != null) {
            System.out.println(line);
            line = bufferedReader.readLine();
        }
        bufferedReader.close();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] a) {
    Map<String, String> map = new HashMap<String, String>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");
    Set set = map.entrySet();

    Iterator iter = set.iterator();

    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();

    }/*from   ww  w  .  j  a  va2s .c o m*/
}

From source file:Main.java

public static void main(String[] a) {
    Map<String, String> map = new HashMap<String, String>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");
    Set set = map.entrySet();

    Iterator iter = set.iterator();

    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        System.out.println(entry.getKey() + " -- " + entry.getValue());
    }//from   w w w.  ja  v a2  s.c om
}

From source file:Main.java

public static void main(String[] args) {
    Map<String, String> unsortMap = new HashMap<String, String>();
    unsortMap.put("1", "1");
    unsortMap.put("2", "A");
    unsortMap.put("3", "2");
    Iterator iterator = unsortMap.entrySet().iterator();
    for (Map.Entry entry : unsortMap.entrySet()) {
        System.out.println("Key : " + entry.getKey() + " Value : " + entry.getValue());
    }//  w  w w . ja  va  2 s  . c  om
    Map<String, String> sortedMap = sortByComparator(unsortMap);
    for (Map.Entry entry : sortedMap.entrySet()) {
        System.out.println("Key : " + entry.getKey() + " Value : " + entry.getValue());
    }
}