public class Demo {
public static void main(String[] args) {
String str = "aabbaccabbcab";
System.out.println(filterCode2(str));
}
public static String filterCode2(String str) {
List list = new ArrayList();
for (int i = 0; i < str.length(); i++) list.add(str.charAt(i) + "");/* 这里就是使用字符串存入到list中,*/
System.out.println(list);
for (int m = 0; m < list.size() - 1; m++)
if (list.get(m).equals(list.get(m + 1))) {
list.remove(m + 1);
list.remove(m);
m = -1;
}
StringBuffer sb = new StringBuffer();
String str3 = "";
for (int j = 0; j < list.size(); j++) str3 = sb.append(list.get(j)).toString();
return str3;
}
}
字符串相邻移除方法
最新推荐文章于 2022-07-11 09:46:16 发布