0

I am having a array like String[] selectedJobs = {"job,1","job,2", "Job2,1", "job3,1"};

I want to extract information like

Job -> 1,2 Job2 -> 1 Job3 -> 1 Map<String, List<String>> jobs = new HashMap<String, List<String>>(); 

and I want to store each job with corresponding list of integers in map.

How to do this ?

0

2 Answers 2

2
  1. split the 1st string on "," -> "job", "1"
  2. check there is a "job" key in the map, if not create it and put a new arraylist for that key
  3. add "1" to the arraylist
  4. loop
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I blocked but your idea "check there is a "job" key in the map, if not create it and put a new arraylist for that key" cleared my error. It is working fine.
1

What have you tried? The algorithm shouldn't be tricky: Go through your array, split on "," for each String, and put it in the HashMap you describe.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.