• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sout

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob Prime ;-))


 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic