Java 1.8 Concurrency feature "ConcurrentHashMap as a Set"
The feature will return set of key in the map as Set.
public class VoiceConcurrentHashMap {
public static void main(String[] args) {
ConcurrentHashMap<String,String> map = new ConcurrentHashMap<String, String>();
System.out.println(map);
map.put("Lnkedin", "Networking");
map.put("Microsoft", "Windows10");
map.put("facebook", "Social");
map.put("Google", "SearchEngine");
KeySetView<String,String> set = map.keySet();
System.out.println(set);
}
}
Result : [Google, facebook, Microsoft, Lnkedin] .
Image :
ref :
Java API
The feature will return set of key in the map as Set.
public class VoiceConcurrentHashMap {
public static void main(String[] args) {
ConcurrentHashMap<String,String> map = new ConcurrentHashMap<String, String>();
System.out.println(map);
map.put("Lnkedin", "Networking");
map.put("Microsoft", "Windows10");
map.put("facebook", "Social");
map.put("Google", "SearchEngine");
KeySetView<String,String> set = map.keySet();
System.out.println(set);
}
}
Result : [Google, facebook, Microsoft, Lnkedin] .
Image :
ref :
Java API
No comments:
Post a Comment