我试图找到从包含至少 5 个元素的 Hashtable 中获取第一项的方法。我有这个:
Hashtable parkingSlots;
parkingSlots = new Hashtable();
parkingSlots.put("P1", null);
parkingSlots.put("P2", null);
parkingSlots.put("P3", null);
parkingSlots.put("P4", null);
parkingSlots.put("P5", null);
Enumeration gPL = parkingSlots.Keys();
While( gPL.hasMoreElements()){
String parkingNum = (String) gPL.nextElement();
**// Here I've this result: P1, P2, P3, P4, P5 but I want to get only the first item, in this case P1**
}