Java Code Examples for java.util.concurrent.ConcurrentHashMap.forEachKey()

The following are Jave code examples for showing how to use forEachKey() of the java.util.concurrent.ConcurrentHashMap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: gauravbytes   File: CollectionImprovements.java   View Source Code Vote up 6 votes
private static void concurrentMapNewFeatures() {
	ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
	map.put("One", "One");
	map.put("One1", "One");
	map.put("One11", "One");
	map.put("One111", "One");
	map.put("One1111", "One");

	map.forEachKey(2, k -> k.length(), System.out::println);
}
 
Example 2
Project: openjdk-jdk10   File: ConcurrentHashMap8Test.java   View Source Code Vote up 6 votes
/**
 * forEachKeySequentially traverses all keys
 */
public void testForEachKeySequentially() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
    assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
}
 
Example 3
Project: openjdk-jdk10   File: ConcurrentHashMap8Test.java   View Source Code Vote up 6 votes
/**
 * forEachKeyInParallel traverses all keys
 */
public void testForEachKeyInParallel() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEachKey(1L, (Long x) -> adder.add(x.longValue()));
    assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
}