Possible Duplicate:
How do I iterate over each Entry in a Map?
I make the personal profiles database,and I use HashMap to collect profile.
private HashMap<String, Profile> database;
but I want to write profile data to text files
PrintWriter fileOut = new PrintWriter(new FileWriter(fileName));
fileOut.println(database.size());
for(int i = 0; i < database.size();i++){
Profile eachProfile = database.get(key);
}
But I don't know how to get list of key to looping How can I get data from HashMap respectively with another ways?
You could use Map.entrySet()
and extended for
:
for (Map.Entry<String, Profile> e: database.entrySet())
{
String s = e.getKey();
Profile p = e.getValue();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With