您的位置:首页 > 职场人生

JAVA面试题之String处理--一字符取出重复的字符以及其个数

2008-04-09 08:46 429 查看
ackage com.test; import java.util.*;

public class Test2 {

public static void main(String args[]){

String s = "abcdad"; //待测试的字符串

Map result = getCharMaps(s);

System.out.println(result);//打印出字符串中各字符出现的次数!

}

public static Map getCharMaps(String s) {

Map map = new HashMap();

for(int i = 0; i < s.length(); i++ ) {

Character c = s.charAt(i);

Integer count = map.get(c); map.put(c, count == null ? 1 : count + 1);

}

return map;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐