Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • 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
  • 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 Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!