字符串去重

来源:互联网 发布:淘宝店铺封了直通车 编辑:程序博客网 时间:2024/05/01 05:18
public class StringRepetition {
public static void main(String[] args) {
System.out.println(withoutRepetion("aaabbc"));
}

public static String withoutRepetion(String s){
if(null == s || s.trim().length() == 0){
return null;
}
String str = "";
for(int i = 0; i < s.length(); i++){
if(str.indexOf(s.substring(i, i+1)) < 0){
str += s.substring(i, i+1);
}
}
return str;
}
}
0 0
原创粉丝点击