• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to convert Map<String,String> to ArrayList<Employee>

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is it possible to convert Map<String,String> to ArrayList<Employee>?

Employee is a class which has name and address fields of type String.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming you want to use the map keys as name and map values as address: yes, it is possible - by writing the necessary code. I don't know of any JDK class or method that would do the work in this case.

What have you tried? Do you have some doubts?

 
Pradeep allada
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no name and address are the fields belongs to Employee like employee name and employee address

I have tried like this
I don't know whether it is correct or not

and to convert them to List



 
Martin Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're getting compile-time error, because the m.values() is a collection of Strings. That ArrayList constructor needs a collection of Employee's.

Java doesn't know how to convert a String to an Employee. You need to do that. You probably also need to code a loop that will go through all the entries in the map.

It might help if you write down all the individual operations you need to do on a piece of paper. And then start to thinking about converting these steps to actual code.
 
And inside of my fortune cookie was this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic