很难用语言表达,所以我会用例子。考虑以下输入:-
Input String = AABBSTUUUX
Output String = ABSTUX
如何在java中实现这一点。
最佳答案
这样就可以了
String word = "AABBSTUUUX";
for (int i = 0; i < word.length() - 1; i++) {
if (word.charAt(i) == word.charAt(i + 1)) {
word.deleteCharAt(i + 1);
}
}
System.out.println(word);
关于java - 从字符串中删除相邻重复项,仅保留一个实例 : java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29218800/