合并字符串中重复出现的字符(java实现)

Posted by 竹林品雨 on November 10, 2013

####合并字符串中重复出现的字符

private String removeDuplicateChar(String str){
    StringBuffer sb = new StringBuffer();
    for(int i = 0; i<str.length(); i++){
        String c = str.substring(i, i+1);
        if(!sb.toString().contains(c)){
            sb.append(c);
        }
    }
    return sb.toString();
}