I found some articles on the Internet and found that they all used the characteristics of data structures to delete repeated characters, so I wrote an efficient wheel myself.
//删除重复的字符
public void delRepeat(String s) {
char buf[]=new char[s.length()];//创建一个辅助的空数组
int sub=0;
boolean find=false;
for(int l=0;l<s.length();l++) {
find=false;
//从头到尾搜索辅助的数组里有没有出现重复的字符
for (int i = 0; i <l; i++) {
if(buf[i]==s.charAt(l)) {
find=true;//标记为找到,后面不进行填充
break;//找到重复的,跳出循环
}
}
//如果在辅助数组没有找到重复的字符,填充该字符
if(find==false)buf[sub++]=s.charAt(l);
}
System.out.println(String.valueOf(buf).trim());
}