【发布时间】:2015-07-30 17:03:16
【问题描述】:
我知道这个问题被问了很多次,但我没有找到任何对我的案例有帮助的答案。我有一个接收字符串的方法。我想检查字符串中的任何字符是否重复。如果是这样,该方法将返回一个空字符串。如果不是,它将返回字符串。 该方法正在寻找字符串中的任何重复字符。
private String visit(String word) {
int count = 0;
if(word == ""){
return "<empty>";
}
//alphabet is an array that holds all characters that could be used in the String
for(int i = 0; i < alphabet.length; i++){
for(int j = 0; j < word.length(); j++){
if(alphabet[i] == word.charAt(j)){
count++;
}
if(count == 2){
return "";
}
}
count = 0;
}
return word;
}
【问题讨论】:
-
I already made a method but its not working correctly, so I won't waste your time and post it here.除了这是问题的一半。我们需要看到它。 -
请提供代码示例。您还可以修改所有其他有用的方法来检查字符是否在字符串中重复以使用字符串的一个字符,并且只是循环遍历字符串的所有字符
-
好的。您是否创建了任何程序或方法来实现这一目标?请分享。
-
您确定字母表包含所有可能的字符吗?
-
查看我的答案,正则表达式可以根据您的需要轻松调整