字符串去重
public class Main{
public static void main(String[] args) {
String string = "afjhafadfgfas";
String string1 = RemoveDuplication(string);
System.out.println(string1);
}
public static String RemoveDuplication(String string) {
//创建一个数组用于存放没有重复的字符串
List list = new ArrayList();
for (int i = 0; i < string.length(); i++) {
//如果list已经有该字符了,则调到下一次循环
if (list.contains(string.charAt(i))) {
continue;
} else {
//否则都是不重复的字符,加入list中
list.add(string.charAt(i));
}
}
return list.toString();
}
}