public static void main(String[] args) {
String str = "abbaddxyyu";
char result = 0;
char tempChar = 0;
char[] testData = str.toCharArray();
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < testData.length; i++) {
tempChar = testData[i];
if (stringBuffer.toString().lastIndexOf(tempChar) == -1) {
if (result == 0) {
result = tempChar;
}
}
stringBuffer.append(tempChar);
for (int j = i + 1; j < testData.length; j++) {
System.out.println("result=" + result + "->tempChar=" + tempChar + "->testData=" + testData[j]);
if (tempChar == testData[j]) {
if(result==tempChar){
result = 0;
}
break;
}
}
}
System.out.println("result=" + result);
}
思路:取不同值临时保存,如果后续重复则制空