You can also try this to get the whole first entry,
Map.Entry<String, String> entry = map.entrySet().stream().findFirst().get(); String key = entry.getKey(); String value = entry.getValue();
This is to get only the key of the first record,
String key = map.entrySet().stream().map(Map.Entry::getKey).findFirst().get();
This is to get only the value of the first record,
String value = map.entrySet().stream().map(Map.Entry::getValue).findFirst().get();
Moreover, if you know what you are doing and want to get the second (same for the third, etc.) Map Element, you should try this,
Map.Entry<String, String> entry = map.entrySet().stream().skip(1).findFirst().get(); String key = map.keySet().stream().skip(1).findFirst().get(); String value = map.values().stream().skip(1).findFirst().get();
George Siggouroglou Aug 22 2018-18-18T00: 00Z
source share