Home How to efficiently iterate over each Entry in a Map?
Reply: 30

How to efficiently iterate over each Entry in a Map?

iMack
1#
iMack Published in 2008-09-05 21:12:48Z

If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map?

Will the ordering of elements depend on the specific map implementation that I have for the interface?

jpaugh
2#
jpaugh Reply to 2016-01-26 20:37:37Z
Map<String, String> map = ...
for (Map.Entry<String, String> entry : map.entrySet())
{
    System.out.println(entry.getKey() + "/" + entry.getValue());
}
pkaeding
3#
pkaeding Reply to 2008-09-05 21:28:18Z

Yes, the order depends on the specific Map implementation.

@ScArcher2 has the more elegant Java 1.5 syntax. In 1.4, I would do something like this:

Iterator entries = myMap.entrySet().iterator();
while (entries.hasNext()) {
  Entry thisEntry = (Entry) entries.next();
  Object key = thisEntry.getKey();
  Object value = thisEntry.getValue();
  // ...
}
Pritam Banerjee
4#
Pritam Banerjee Reply to 2017-05-04 22:39:46Z

In theory, the most efficient way will depend on which implementation of Map. The official way to do this is to call map.entrySet(), which returns a set of Map.Entry, each of which contains a key and a value (entry.getKey() and entry.getValue()).

In an idiosyncratic implementation, it might make some difference whether you use map.keySet(), map.entrySet() or something else. But I can't think of a reason why anyone would write it like that. Most likely it makes no difference to performance what you do.

And yes, the order will depend on the implementation - as well as (possibly) the order of insertion and other hard-to-control factors.

[edit] I wrote valueSet() originally but of course entrySet() is actually the answer.

marko
5#
marko Reply to 2016-01-01 22:04:45Z

Typical code for iterating over a map is:

Map<String,Thing> map = ...;
for (Map.Entry<String,Thing> entry : map.entrySet()) {
    String key = entry.getKey();
    Thing thing = entry.getValue();
    ...
}

HashMap is the canonical map implementation and doesn't make guarantees (or though it should not change order if no mutating operation are performed on it). SortedMap will return entries based on the natural ordering of the keys, or a Comparator, if provided. LinkedHashMap will either return entries in insertion-order or access-order depending upon how it has been constructed. EnumMap returns entries in natural order of keys.

Note, IdentityHashMap entrySet iterator currently has a peculiar implementation which returns the same Map.Entry instance for every item in the entrySet! However, every time a new the iterator advances the Map.Entry is updated.

Community
6#
Community Reply to 2017-05-23 11:47:32Z

This is a two part question:

How to iterate over the entries of a Map - @ScArcher2 has answered that perfectly.

What is the order of iteration - if you are just using Map, then strictly speaking, there are no ordering guarantees. So you shouldn't really rely on the ordering given by any implementation. However, the SortedMap interface extends Map and provides exactly what you are looking for - implementations will aways give a consistent sort order.

NavigableMap is another useful extension - this is a SortedMap with additional methods for finding entries by their ordered position in the key set. So potentially this can remove the need for iterating in the first place - you might be able to find the specific entry you are after using the higherEntry, lowerEntry, ceilingEntry, or floorEntry methods. The descendingMap method even gives you an explicit method of reversing the traversal order.

ckpwong
7#
ckpwong Reply to 2008-09-05 22:27:52Z

FYI, you can also use map.keySet() and map.values() if you're only interested in keys/values of the map and not the other.

Chris Dail
8#
Chris Dail Reply to 2011-10-17 00:16:44Z

The correct way to do this is to use the accepted answer as it is the most efficient. I find the following code looks a bit cleaner.

for (String key: map.keySet()) {
   System.out.println(key + "/" + map.get(key));
}
serg
9#
serg Reply to 2009-08-18 17:34:51Z

Example of using iterator and generics:

Iterator<Map.Entry<String, String>> entries = myMap.entrySet().iterator();
while (entries.hasNext()) {
  Map.Entry<String, String> entry = entries.next();
  String key = entry.getKey();
  String value = entry.getValue();
  // ...
}
bluish
10#
bluish Reply to 2013-06-07 14:34:44Z

Try this with Java 1.4:

for( Iterator entries = myMap.entrySet().iterator(); entries.hasNext();){

  Entry entry = (Entry) entries.next();

  System.out.println(entry.getKey() + "/" + entry.getValue());

  //...
}
bluish
11#
bluish Reply to 2013-06-07 14:34:13Z
public class abcd{
    public static void main(String[] args)
    {
       Map<Integer, String> testMap = new HashMap<Integer, String>();
        testMap.put(10, "a");
        testMap.put(20, "b");
        testMap.put(30, "c");
        testMap.put(40, "d");
        for (Integer key:testMap.keySet()) {
            String value=testMap.get(key);
            System.out.println(value);
        }
    }
}

OR

public class abcd {
    public static void main(String[] args)
    {
       Map<Integer, String> testMap = new HashMap<Integer, String>();
        testMap.put(10, "a");
        testMap.put(20, "b");
        testMap.put(30, "c");
        testMap.put(40, "d");
        for (Entry<Integer, String> entry : testMap.entrySet()) {
            Integer key=entry.getKey();
            String value=entry.getValue();
        }
    }
}
Donald Raab
12#
Donald Raab Reply to 2016-01-10 22:10:22Z

With Eclipse Collections (formerly GS Collections), you would use the forEachKeyValue method on the MapIterable interface, which is inherited by the MutableMap and ImmutableMap interfaces and their implementations.

final MutableBag<String> result = Bags.mutable.empty();
MutableMap<Integer, String> map = Maps.mutable.of(1, "One", 2, "Two", 3, "Three");
map.forEachKeyValue(new Procedure2<Integer, String>()
{
    public void value(Integer key, String value)
    {
        result.add(key + value);
    }
});
Assert.assertEquals(Bags.mutable.of("1One", "2Two", "3Three"), result);

With Java 8 lambda syntax, you can write the code as follows:

MutableBag<String> result = Bags.mutable.empty();
MutableMap<Integer, String> map = Maps.mutable.of(1, "One", 2, "Two", 3, "Three");
map.forEachKeyValue((key, value) -> { result.add(key + value);});
Assert.assertEquals(Bags.mutable.of("1One", "2Two", "3Three"), result);

Note: I am a committer for Eclipse Collections.

ꜱᴜʀᴇꜱʜ ᴀᴛᴛᴀ
13#
ꜱᴜʀᴇꜱʜ ᴀᴛᴛᴀ Reply to 2013-03-21 19:49:53Z

Yes, as many people agreed this is the best way to iterate over MAP.

But there are chances to throw nullpointerexception if map is null.Don't forget to put null .check

                                                  | 
                                                  |  
                                          - - - - 
                                        |
                                        |          
 for (Map.Entry<String, Object> entry : map.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();

}
Alex Weitz
14#
Alex Weitz Reply to 2016-03-16 15:54:24Z

You can do it using generics:

Map<Integer, Integer> map = new HashMap<Integer, Integer>();
Iterator<Map.Entry<Integer, Integer>> entries = map.entrySet().iterator();
while (entries.hasNext()) {
    Map.Entry<Integer, Integer> entry = entries.next();
    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
Saint Hill
15#
Saint Hill Reply to 2016-09-07 08:33:17Z

In Java 8 you can do it clean and fast using the new lambdas features:

 Map<String,String> map = new HashMap<>();
 map.put("SomeKey", "SomeValue");
 map.forEach( (k,v) -> [do something with key and value] );

 // such as
 map.forEach( (k,v) -> System.out.println("Key: " + k + ": Value: " + v));

The type of k and v will be inferred by the compiler and there is no need to use Map.Entry anymore.

Easy-peasy!

Alex Weitz
16#
Alex Weitz Reply to 2016-03-16 16:17:58Z

If you have a generic untyped Map you can use:

Map map = new HashMap();
for (Map.Entry entry : ((Set<Map.Entry>) map.entrySet())) {
    System.out.println(entry.getKey() + "/" + entry.getValue());
}
J.B.Vala
17#
J.B.Vala Reply to 2014-01-03 12:28:28Z

There are the several way to iterate a map please refer the following code When you iterate a map using iterator Interface you must to go with Entry or entrySet() look like this

import java.util.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class IteratMapDemo{
public static void main(String arg[]){
Map<String,String> mapOne =new HashMap<String,String>();
   mapOne.put("1","January");
   mapOne.put("2","February");
   mapOne.put("3","March");
   mapOne.put("4","April");
   mapOne.put("5","May");
   mapOne.put("6","June");
   mapOne.put("7","July");
   mapOne.put("8","August");
   mapOne.put("9","September");
   mapOne.put("10","Octomber");
   mapOne.put("11","November");
   mapOne.put("12","December"); 

    Iterator it = mapOne.entrySet().iterator();
    while(it.hasNext())
    {
        Map.Entry me=(Map.Entry) it.next();
        //System.out.println("Get Key through While loop = " +me.getKey());
    }
    for(Map.Entry<String,String> entry:mapOne.entrySet()){
        //System.out.println(entry.getKey() + "=" +entry.getValue() );
    }

    for (Object key : mapOne.keySet()) {
    System.out.println("Key : " + key.toString() + " Value : "
        + mapOne.get(key));
}

}
}
Rupesh Yadav
18#
Rupesh Yadav Reply to 2014-01-29 12:35:03Z

In Map one can Iteration over keys and/or values and/or both (e.g., entrySet) depends on one's interested in_ Like:

1.) Iterate through the keys -> keySet() of the map:

Map<String, Object> map = ...;

for (String key : map.keySet()) {
    //your Business logic...
}

2.) Iterate through the values -> values() of the map:

for (Object value : map.values()) {
    //your Business logic...
}

3.) Iterate through the both -> entrySet() of the map:

for (Map.Entry<String, Object> entry : map.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();
    //your Business logic...
}

Moreover, there are 3 difference ways to Iterate Through a HashMap. They are as below_

//1.
for (Map.Entry entry : hm.entrySet()) {
    System.out.print("key,val: ");
    System.out.println(entry.getKey() + "," + entry.getValue());
}

//2.
Iterator iter = hm.keySet().iterator();
while(iter.hasNext()) {
    Integer key = (Integer)iter.next();
    String val = (String)hm.get(key);
    System.out.println("key,val: " + key + "," + val);
}

//3.
Iterator it = hm.entrySet().iterator();
while (it.hasNext()) {
    Map.Entry entry = (Map.Entry) it.next();
    Integer key = (Integer)entry.getKey();
    String val = (String)entry.getValue();
    System.out.println("key,val: " + key + "," + val);
}
James Z
19#
James Z Reply to 2015-07-18 15:58:26Z

There are several ways to iterate over map.

Here is comparison of their performances for a common data set stored in map by storing a million key value pairs in map and will iterate over map.

1) Using entrySet() in for each loop

for (Map.Entry<String,Integer> entry : testMap.entrySet()) {
    entry.getKey();
    entry.getValue();
}

50 milliseconds

2) Using keySet() in for each loop

for (String key : testMap.keySet()) {
    testMap.get(key);
}

76 milliseconds

3) Using entrySet() and iterator

Iterator<Map.Entry<String,Integer>> itr1 = testMap.entrySet().iterator();
while(itr1.hasNext()) {
    Map.Entry<String,Integer> entry = itr1.next();
    entry.getKey();
    entry.getValue();
}

50 milliseconds

4) Using keySet() and iterator

Iterator itr2 = testMap.keySet().iterator();
while(itr2.hasNext()) {
    String key = itr2.next();
    testMap.get(key);
}

75 milliseconds

I have referred this link.

ROMANIA_engineer
20#
ROMANIA_engineer Reply to 2014-09-24 11:37:45Z
Iterator itr2 = testMap.keySet().iterator();
while (itr2.hasNext()) {
    String key = itr2.next();
    testMap.get(key);
}

for (String key: map.keySet()) {    
    System.out.println(key + "/" + map.get(key)); 
}

The best way is entrySet() though.

Petro
21#
Petro Reply to 2016-01-14 20:58:30Z
    Iterator iterator = map.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry element = (Map.Entry)it.next();
        LOGGER.debug("Key: " + element.getKey());
        LOGGER.debug("value: " + element.getValue());    
    }
George Siggouroglou
22#
George Siggouroglou Reply to 2014-08-04 10:30:49Z

JAVA 8
You can use Lambda Expressions.

myMap.entrySet().stream().forEach((entry) -> {
    Object currentKey = entry.getKey();
    Object currentValue = entry.getValue();
});

For more information follow this.

fechidal89
23#
fechidal89 Reply to 2014-08-21 22:15:17Z

I copied the data of a map to another with this code:

HashMap product =(HashMap)shopping_truck.get(i);
HashMap tmp = new HashMap();
for (Iterator it = product.entrySet().iterator(); it.hasNext();) {
    Map.Entry thisEntry = (Map.Entry) it.next();
    tmp.put(thisEntry.getKey(), thisEntry.getValue());
}
JohnK
24#
JohnK Reply to 2015-01-10 00:22:38Z

It doesn't quite answer the OP's question, but might be useful to others who find this page:

If you only need the values and not the keys, you can do this:

Map<Ktype, Vtype> myMap = [...];
for (Vtype v: myMap.values()) {
  System.out.println("value: " + v);
}

Ktype, Vtype are pseudocode.

Mr. Polywhirl
25#
Mr. Polywhirl Reply to 2015-05-13 12:49:00Z

Here is a generic; type-safe method which can be called to dump any given Map.

import java.util.Iterator;
import java.util.Map;

public class MapUtils {
    static interface ItemCallback<K, V> {
        void handler(K key, V value, Map<K, V> map);
    }

    public static <K, V> void forEach(Map<K, V> map, ItemCallback<K, V> callback) {
        Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();

        while (it.hasNext()) {
            Map.Entry<K, V> entry = it.next();

            callback.handler(entry.getKey(), entry.getValue(), map);
        }
    }

    public static <K, V> void printMap(Map<K, V> map) {
        forEach(map, new ItemCallback<K, V>() {
            @Override
            public void handler(K key, V value, Map<K, V> map) {
                System.out.println(key + " = " + value);
            }
        });
    }
}

Example

Here is an example of it's use. Notice that they type of the Map is inferred by the method.

import java.util.*;

public class MapPrinter {
    public static void main(String[] args) {
        List<Map<?, ?>> maps = new ArrayList<Map<?, ?>>() {
            private static final long serialVersionUID = 1L;
            {
                add(new LinkedHashMap<String, Integer>() {
                    private static final long serialVersionUID = 1L;
                    {
                        put("One", 0);
                        put("Two", 1);
                        put("Three", 3);
                    }
                });

                add(new LinkedHashMap<String, Object>() {
                    private static final long serialVersionUID = 1L;
                    {
                        put("Object", new Object());
                        put("Integer", new Integer(0));
                        put("Double", new Double(0.0));
                    }
                });
            }
        };

        for (Map<?, ?> map : maps) {
            MapUtils.printMap(map);
            System.out.println();
        }
    }
}

Output

One = 0
Two = 1
Three = 3

Object = java.lang.Object@15db9742
Integer = 0
Double = 0.0
Joshua Michael Calafell
26#
Joshua Michael Calafell Reply to 2015-05-31 02:05:27Z

This is the easiest way of doing it I believe...

/* For example, this could be a map object */
Map<String, Integer> MAP = new Map<>();

// Do something like put keys/value pairs into the map, etc...
MAP.put("Denver", 35);
MAP.put("Patriots", 14);

/* Then, simply use a for each loop like this to iterate */
for (Object o : MAP.entrySet()) {
    Map.Entry pair = (Map.Entry) o;
    // Do whatever with the pair here (i.e. pair.getKey(), or pair.getValue();
}
tomaj
27#
tomaj Reply to 2015-08-29 17:11:44Z

If your reason for iterating trough the Map, is to do an operation on the value and write to a resulting Map. I recommend using the transform-methods in the Google Guava Maps class.

import com.google.common.collect.Maps;

After you have added the Maps to your imports, you can use Maps.transformValues and Maps.transformEntries on your maps, like this:

public void transformMap(){
    Map<String, Integer> map = new HashMap<>();
    map.put("a", 2);
    map.put("b", 4);

    Map<String, Integer> result = Maps.transformValues(map, num -> num * 2);
    result.forEach((key, val) -> print(key, Integer.toString(val)));
    // key=a,value=4
    // key=b,value=8

    Map<String, String> result2 = Maps.transformEntries(map, (key, value) -> value + "[" + key + "]");
    result2.forEach(this::print);
    // key=a,value=2[a]
    // key=b,value=4[b]
}

private void print(String key, String val){
    System.out.println("key=" + key + ",value=" + val);
}
i_am_zero
28#
i_am_zero Reply to 2015-09-02 01:13:29Z

In Java 8 we have got forEach method that accepts a lambda expression. We have also got stream APIs. Consider a map:

Map<String,String> sample = new HashMap<>();
sample.put("A","Apple");
sample.put("B", "Ball");

Iterate over keys:

sample.keySet().forEach((k) -> System.out.println(k));

Iterate over values:

sample.values().forEach((v) -> System.out.println(v));

Iterate over entries (Using forEach and Streams):

sample.forEach((k,v) -> System.out.println(k + "=" + v)); 
sample.entrySet().stream().forEach((entry) -> {
            Object currentKey = entry.getKey();
            Object currentValue = entry.getValue();
            System.out.println(currentKey + "=" + currentValue);
        });

The advantage with streams is they can be parallelized easily in case we want to. We simply need to use parallelStream() in place of stream() above.

Alex Weitz
29#
Alex Weitz Reply to 2016-03-16 15:38:05Z

Lambda Expression Java 8

In Java 1.8 (Java 8) this has become lot easier by using forEach method from Aggregate operations(Stream operations) that looks similar to iterators from Iterable Interface.

Just copy paste below statement to your code and rename the HashMap variable from hm to your HashMap variable to print out key-value pair.

HashMap<Integer,Integer> hm = new HashMap<Integer, Integer>();
/*
 *     Logic to put the Key,Value pair in your HashMap hm
 */

// Print the key value pair in one line.

hm.forEach((k,v) -> System.out.println("key: "+k+" value:"+v));

// Just copy and paste above line to your code.

Below is the sample code that i tried using Lambda Expression. This stuff is so cool. Must try.

HashMap<Integer,Integer> hm = new HashMap<Integer, Integer>();
    Random rand = new Random(47);
    int i=0;
    while(i<5){
        i++;
        int key = rand.nextInt(20);
        int value = rand.nextInt(50);
        System.out.println("Inserting key: "+key+" Value: "+value);
        Integer imap =hm.put(key,value);
        if( imap == null){
            System.out.println("Inserted");
        }
        else{
            System.out.println("Replaced with "+imap);
        }               
    }

    hm.forEach((k,v) -> System.out.println("key: "+k+" value:"+v));

Output:

Inserting key: 18 Value: 5
Inserted
Inserting key: 13 Value: 11
Inserted
Inserting key: 1 Value: 29
Inserted
Inserting key: 8 Value: 0
Inserted
Inserting key: 2 Value: 7
Inserted
key: 1 value:29
key: 18 value:5
key: 2 value:7
key: 8 value:0
key: 13 value:11

Also one can use Spliterator for the same.

Spliterator sit = hm.entrySet().spliterator();

UPDATE


Including documentation links to Oracle Docs. For more on Lambda go to this link and must read Aggregate Operations and for Spliterator go to this link.

Syd Lambert
30#
Syd Lambert Reply to 2015-10-27 18:09:34Z

If you want to iterate through the map in the order that the elements were added, use LinkedHashMap as opposed to just Map.

This approach has worked for me in the past:

LinkedHashMap<String,Integer> test=new LinkedHashMap();

test.put("foo",69);
test.put("bar",1337);

for(int i=0;i<test.size();i++){
    System.out.println(test.get(test.keySet().toArray()[i]));
}

Output:

69
1337
vancy.pants
31#
vancy.pants Reply to 2018-01-17 18:53:09Z

To summarize the other answers and combine them with what I know, I found 10 main ways to do this (see below). Also, I wrote some performance tests (see results below). For example, if we want to find the sum of all of the keys and values of a map, we can write :

  1. Using iterator and Map.Entry

    long i = 0;
    Iterator<Map.Entry<Integer, Integer>> it = map.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<Integer, Integer> pair = it.next();
        i += pair.getKey() + pair.getValue();
    }
    
  2. Using foreach and Map.Entry

    long i = 0;
    for (Map.Entry<Integer, Integer> pair : map.entrySet()) {
        i += pair.getKey() + pair.getValue();
    }
    
  3. Using forEach from Java 8

    final long[] i = {0};
    map.forEach((k, v) -> i[0] += k + v);
    
  4. Using keySet and foreach

    long i = 0;
    for (Integer key : map.keySet()) {
        i += key + map.get(key);
    }
    
  5. Using keySet and iterator

    long i = 0;
    Iterator<Integer> itr2 = map.keySet().iterator();
    while (itr2.hasNext()) {
        Integer key = itr2.next();
        i += key + map.get(key);
    }
    
  6. Using for and Map.Entry

    long i = 0;
    for (Iterator<Map.Entry<Integer, Integer>> entries = map.entrySet().iterator(); entries.hasNext(); ) {
        Map.Entry<Integer, Integer> entry = entries.next();
        i += entry.getKey() + entry.getValue();
    }
    
  7. Using Java 8 Stream Api

    final long[] i = {0};
    map.entrySet().stream().forEach(e -> i[0] += e.getKey() + e.getValue());
    
  8. Using Java 8 Stream Api parallel

    final long[] i = {0};
    map.entrySet().stream().parallel().forEach(e -> i[0] += e.getKey() + e.getValue());
    
  9. Using IterableMap of Apache Collections

    long i = 0;
    MapIterator<Integer, Integer> it = iterableMap.mapIterator();
    while (it.hasNext()) {
        i += it.next() + it.getValue();
    }
    
  10. Using MutableMap of Eclipse (CS) collections

    final long[] i = {0};
    mutableMap.forEachKeyValue((key, value) -> {
        i[0] += key + value;
    });
    

Perfomance tests (mode = AverageTime, system = Win 8.1 64-bit, Intel i7-4790 3.60GHz 3.60GHz, 16 GB)

1) For small map (100 elements), score 0.308 is the best

       Benchmark                      Mode  Cnt     Score      Error  Units
test3_UsingForEachAndJava8            avgt   10     0.308 ±    0.021  us/op
test10_UsingEclipseMap                avgt   10     0.309 ±    0.009  us/op
test1_UsingWhileAndMapEntry           avgt   10     0.380 ±    0.014  us/op
test6_UsingForAndIterator             avgt   10     0.387 ±    0.016  us/op
test2_UsingForEachAndMapEntry         avgt   10     0.391 ±    0.023  us/op
test7_UsingJava8StreamApi             avgt   10     0.510 ±    0.014  us/op
test9_UsingApacheIterableMap          avgt   10     0.524 ±    0.008  us/op
test4_UsingKeySetAndForEach           avgt   10     0.816 ±    0.026  us/op
test5_UsingKeySetAndIterator          avgt   10     0.863 ±    0.025  us/op
test8_UsingJava8StreamApiParallel     avgt   10     5.552 ±    0.185  us/op

2) For map with 10000 elements, score 37.606 is the best

       Benchmark                    Mode  Cnt     Score      Error  Units
test10_UsingEclipseMap              avgt   10    37.606 ±    0.790  us/op
test3_UsingForEachAndJava8          avgt   10    50.368 ±    0.887  us/op
test6_UsingForAndIterator           avgt   10    50.332 ±    0.507  us/op
test2_UsingForEachAndMapEntry       avgt   10    51.406 ±    1.032  us/op
test1_UsingWhileAndMapEntry         avgt   10    52.538 ±    2.431  us/op
test7_UsingJava8StreamApi           avgt   10    54.464 ±    0.712  us/op
test4_UsingKeySetAndForEach         avgt   10    79.016 ±   25.345  us/op
test5_UsingKeySetAndIterator        avgt   10    91.105 ±   10.220  us/op
test8_UsingJava8StreamApiParallel   avgt   10   112.511 ±    0.365  us/op
test9_UsingApacheIterableMap        avgt   10   125.714 ±    1.935  us/op

3) For map with 100000 elements, score 1184.767 is the best

       Benchmark                   Mode  Cnt     Score      Error  Units
test1_UsingWhileAndMapEntry        avgt   10  1184.767 ±  332.968  us/op
test10_UsingEclipseMap             avgt   10  1191.735 ±  304.273  us/op
test2_UsingForEachAndMapEntry      avgt   10  1205.815 ±  366.043  us/op
test6_UsingForAndIterator          avgt   10  1206.873 ±  367.272  us/op
test8_UsingJava8StreamApiParallel  avgt   10  1485.895 ±  233.143  us/op
test5_UsingKeySetAndIterator       avgt   10  1540.281 ±  357.497  us/op
test4_UsingKeySetAndForEach        avgt   10  1593.342 ±  294.417  us/op
test3_UsingForEachAndJava8         avgt   10  1666.296 ±  126.443  us/op
test7_UsingJava8StreamApi          avgt   10  1706.676 ±  436.867  us/op
test9_UsingApacheIterableMap       avgt   10  3289.866 ± 1445.564  us/op

Graphs (perfomance tests depending on map size)

Table (perfomance tests depending on map size)

         100     600     1100    1600    2100
test10  0.333   1.631   2.752   5.937   8.024
test3   0.309   1.971   4.147   8.147   10.473
test6   0.372   2.19    4.47    8.322   10.531
test1   0.405   2.237   4.616   8.645   10.707
test2   0.376   2.267   4.809   8.403   10.91
test7   0.473   2.448   5.668   9.79    12.125
test9   0.565   2.83    5.952   13.22   16.965
test4   0.808   5.012   8.813   13.939  17.407
test5   0.81    5.104   8.533   14.064  17.422
test8   5.173   12.499  17.351  24.671  30.403

All test in github

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.417405 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO