我有这个方法用于java 1.6。但这不适用于 java 1.4.2。我才知道这是从 1.5 引入的。那么,在 1.4.2 中还有其他等效的方法吗?
Set keys = this.getMap().keySet();
for (String key :keys){...
..
}
你需要一个老式的迭代器:
// Old skool set (no generics)
Set foo = new HashSet();
foo.add("bar");
foo.add("frobnicate");
// Old skool iterator (no generics, needs typecasting)
Iterator iFoo = foo.iterator();
while (iFoo.hasNext())
{
String something = (String)iFoo.next();
}
使用Iterator
.
Iterator it = this.getMap().keySet().iterator();
while(it.hasNext()) {
// do stuff
String s = (String)it.next();
}