Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Map Conversion

 
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

I'm having this problem on data type conversion between a map and a string array and outputting the result.



What I expect for the output is the manner at which I add it to the map.
My expected output was "one", "two","three","four"..."eight" and this is the sequential way on how I add the object to the map.

But when i ran the code, the output gets jammed "eight", "five","four","one"...."two".

By the way, I did some test and change the collection type from a Map to an ArrayList. I then perform String array conversion, and the output was the manner how I add it to the arraylist. But I dont need an arraylist but a map. I'm wondering whats the difference between a map and arraylist conversion to string array?

Is there a way for me to have my output be synchronized in the manner I inserted it my collection(map)? I'm running in circles thinking of possible ways on how to execute this. Need some advice. Thanks to all ranchers..
 
author
Posts: 23926
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is there a way for me to have my output be synchronized in the manner I inserted it my collection(map)? I'm running in circles thinking of possible ways on how to execute this. Need some advice. Thanks to all ranchers..



Take a look at the java.util.LinkedHashMap.

Henry
 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Henry, Thanks a Lot..

My code gets running as I expected it to be..
 
reply
    Bookmark Topic Watch Topic
  • New Topic