This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes sout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sout" Watch "sout" New topic
Author

sout

Lenny Peter
Ranch Hand

Joined: Apr 22, 2008
Posts: 52
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

Joined: Oct 27, 2005
Posts: 19674
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Lenny Peter
Ranch Hand

Joined: Apr 22, 2008
Posts: 52
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

Joined: Oct 27, 2005
Posts: 19674
    
  18

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

Joined: Apr 22, 2008
Posts: 52
Thanks Rob Prime ;-))


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sout