public static void main(String[] args) { String strArray[]={"3=10", "2=10", "1=30", "7=10", "6=10", "5=10", "4=10", "9=10", "8=10"};
Map<String,String> map = new HashMap<String,String>();
for(int i=0;i<strArray.length;i++){
map.put(strArray[i].split("=")[0], strArray[i].split("=")[1]);
}
System.out.println(map.toString());
}

解决方案 »

  1.   

    public static void main(String[] args) { String str="{3=10, 2=10, 1=30, 7=10, 6=10, 5=10, 4=10, 9=10, 8=10}";
    String strArray[]=str.substring(1,str.length()-1).split(","); 
    Map<String,String> map = new HashMap<String,String>();
    for(int i=0;i<strArray.length;i++){
    map.put(strArray[i].split("=")[0], strArray[i].split("=")[1]);
    }
    System.out.println(map.toString());
    }
      

  2.   

    最好用正则吧Map<Integer, Integer> map = new HashMap<Integer, Integer>();        String line = "{3=10, 2=10, 1=30, 7=10, 6=10, 5=10, 4=10, 9=10, 8=10}";
            Pattern pattern = Pattern.compile("(\\d+)=(\\d+)");
            Matcher matcher = pattern.matcher(line);
            while(matcher.find()) {
                map.put(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)));
            }
            for(Map.Entry<Integer, Integer> entry : map.entrySet()) {
                System.out.println(String.format("key: %d value: %d", entry.getKey(), entry.getValue()));
            }