|
|
|
public class Test3 { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); //输出提示语 System.out.println("请输入字符串 附:字符串之间用,隔开"); //读取输入字符串 String temp=br.readLine(); Map maps = new HashMap(); String[] templist = temp.split(","); for(int i = 0 ; i < templist.length;i++){ //准备放map String t = templist[i]; //判断key boolean is = maps.containsKey(t); if(is == true){ //++1 Integer vs = (Integer)maps.get(t); vs++; maps.put(t, vs); }else{ //放`1 maps.put(t, 1); } } System.out.println(maps); } } |
|