第一次迭代,就是第一条记录,使用如下
map.entrySet().iterator().next()
public static void main(String[] args) throws IOException {
Map<String, Integer> cc=new HashMap<>();
cc.put("dsfs",1);
cc.put("dsfs1",144);
cc.put("dsfs2",13453);
cc.put("dsfs3",156);
System.out.println(getFirstDataFromMap(cc));
}
public static String getFirstDataFromMap(Map<String, Integer> map){
Map.Entry<String, Integer> firstEntry = map.entrySet().iterator().next();
String firstKey = firstEntry.getKey();
Integer firstValue = firstEntry.getValue();
return firstKey+"="+firstValue;
}
输出
{dsfs2=13453, dsfs3=156, dsfs1=144, dsfs=1}
dsfs3=156