Java tutorial
//package com.java2s; import java.util.Map; import java.util.NoSuchElementException; public class Main { public static <K, V> Map.Entry<K, V> getFirstEntry(Map<K, V> map) { try { return map.entrySet().iterator().next(); } catch (NullPointerException e) { return null; } catch (NoSuchElementException e) { return null; } } }