my dog learned polymorphism*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 19649
    
  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: 19649
    
  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: 37926
    
  22
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.
 
jQuery in Action, 2nd edition
 
subject: sout
 
Similar Threads
Drop Downs
array to object - why?
Validating String aginst schema directly
Enums and switch
bad using method get()