How to get First Key value from HashMap in java
Example:
Output:Key is FIRST value FIRST
Approach
Java
import java.util.HashMap;import java.util.LinkedHashMap;public class HashMapFirstKeyValues {public static void main(String[] args) {HashMap<String, String> map = new LinkedHashMap<>();map.put("FIRST", "FIRST");map.put("SECOND", "SECOND");map.put("THIRD", "THIRD");String key = map.keySet().iterator().next();System.out.println("Key is " + key + " value " + map.get(key));}}
No comments:
Post a Comment