aspose file tools*
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
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: 19762
    
  20

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: 19762
    
  20

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: 39869
    
  28
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.
 
Consider Paul's rocket mass heater.
 
subject: sout