Link to home
Start Free TrialLog in
Avatar of srikotesh
srikotesh

asked on

how to iterate duplicate list values and set to map object in java

Hi Experts,

i am getting list of object values from db.
i have to iterate and set to map object
if the duplicate is repeated i need to verify it is already added to the map or not
if it is already added to the map then i need to check the status
if the status is delivered in first object itself. no need to update the status
if the status is inprogress or pending i need to update the status in map

public class Problem{
private String problemName;
private String status;

setters and getters...

}

public class ProblemDto{
private Map<String,Problem> problems;
setters and getters..
}

List<Object> details = dataFromDao.getproblemsData(); //getting the data from database
Map<String,Problem> resultMap= new HashMap<>();
for(Object object :detaisl){
Object[] row = (Object[])object;
final Problem problem = new Problem();
problem.setProblemName((String) row[0]);
problem.setStatus((String) row[1]);
map.put((String)row[0],problem);
}

Open in new window


details list contains duplicated problem names and status
map will not allow duplicates.but i need to update status

let suppose i am getting the values from db like

laptopproblem   pending
telephoneproblem  completed
computerproblem  inprogress
//duplicate values
laptopproblem    delivered

in map i need to check laptopproblem instead of pending i need to replace with delivered.

laptop problem   inprogress

if i got one more duplicate problemname i no need to update, if the status is delivered no need to update  if not i have to update the status

how to do can some one suggest me
ASKER CERTIFIED SOLUTION
Avatar of gurpsbassi
gurpsbassi
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of srikotesh
srikotesh

ASKER

Excellent