Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sout

 
Lenny Peter
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

How can I get this to look like...

Audi Sedan 1958,
BMW St. Car 1951





result: [Audi Sedan 1958, BMW St. Car 1951]
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You already know how to get the values; all you need to do is find a way to iterate over them. I'm sure you can find a nice method if you look into the Collection Javadoc.
 
Lenny Peter
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried with..




result:
4711Due=Audi Sedan 1958
4711Trio=BMW St. Car 1951


but it should be without the key..?
Audi Sedan 1958,
BMW St. Car 1951
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) your Iterator now returns instances of Map.Entry<String,String>. You can get the value with one of its methods.
2) why did you switch from values() to entrySet()?

You may also want to check out the "enhanced for-loop" a.k.a. the "for-each loop".
 
Lenny Peter
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob Prime ;-))


 
Campbell Ritchie
Sheriff
Posts: 48404
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use more informative titles for your threads, and the code button; I have edited your last post so you can see how much easier it is to read.

Did you get the code to work? In the instance with the iterator which you commented out, tryThat should work. The second attempt at printing looks all right from here. I presume it worked? In fact you seem to have two decent solutions to your problem

Better to declare the Map as Map<String, String> resultMap = new HashMap<etc>(); That way you can swap to a different implementation very easily.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic