• Post Reply Bookmark Topic Watch Topic
  • New Topic

Add a method to the MailServer class called printAllMessages, that iterates through the users, print  RSS feed

 
Chan Duller
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Above is what I have for the method so far, and it compiles. But when I run it, I get the response in the screen shot. I sent two messages to user A. The first issue is that I just want user A: message 1, message 2...etc.
I don't want user A: message 1, user A: message 2, etc. The second issue is that it is not actually returning the emails for the user...it seems to be returning an address. The rest of my code it below.

Screen-Shot-2015-10-29-at-12.27.10-PM.png
[Thumbnail for Screen-Shot-2015-10-29-at-12.27.10-PM.png]
 
Dennis Grimbergen
Ranch Hand
Posts: 159
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chan Duller wrote:

Don't iterate over a keySet and than do a 'get' in each iteration.
Iterate over the entrySet and then use the getKey() and getValue().

Your uninformative representation of MailItem is caused because of the toString() method. MailItem@3a4c56f1 is the result of the toString() method of class Object. This method prints the name of the class and then a @ and then the hexadecimal representation of the hashCode of that object.
If you want it to be more informative, than override the toString() method in MailItem.
 
Chan Duller
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I am just a beginner. Where do I put the getKey() and getValue() part? Do I need to still override the toString() method if I make those changes? And if so, how do I?
Thanks!
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The head of the for loop would look like this:

Then use entry to getKey() and getValue().

If the SOP statement should actually be

then you will still need to override toString() in MailItem. It could look as simple as

assuming messageText means something in MailItem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!