简体   繁体   中英

Extract information from array

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 ?

  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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM