Get First Element in Map Java | Get First value from map Java 8

Try This:

Map<String,String> map = new HashMap<>(); Map.Entry<String,String> entry = map.entrySet().iterator().next(); String key = entry.getKey(); String value = entry.getValue();

Java 8:

Map.Entry<String, String> entry = map.entrySet().stream().findFirst().get();String key = entry.getKey();String value = entry.getValue();