日期:2014-05-20 浏览次数:20764 次
import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; public class Test { public static void main(String[] args) { String str = "FI:Z;P,SC,BE,CT"; Map<String, List<String>> map = process(str); // 遍历输出 for(Map.Entry<String, List<String>> entry : map.entrySet()) { System.out.println(entry.getKey()); List<String> list = entry.getValue(); if(list.size() > 0) { for(String s : list) { System.out.println(" " + s); } }else{ System.out.println(" <null>"); } } } public static Map<String, List<String>> process(String str) { String[] step1 = str.split(","); Map<String, List<String>> map = new LinkedHashMap<String, List<String>>(); for(String s : step1) { String[] step2 = s.split(":"); List<String> list = new ArrayList<String>(); if(step2.length > 1) { String[] step3 = step2[1].split(";"); list = Arrays.asList(step3); } map.put(step2[0], list); } return map; } }