1.
public class TestString {
public static void main(String args[]){String a = "teststst";
for(int i = 0 ; i < a.length();i++){
char s = a.charAt(i);
if(a.indexOf(s) == a.lastIndexOf(s)){
System.out.println(s);
}
}
}
}
2.
public class TestString1 {
public void Cal(String s) {
int n = 0;
for(int i = 0 ; i < s.length();i++){
char t = s.charAt(i);
for(int j = 0 ; j < s.length();j++){
char tt = s.charAt(j);
if(t == tt){
n+=1;
}
}
if(n == 1){
System.out.println("out result: "+t);
break;
}
n = 0;
}
}
public static void main(String args[]) {
TestString1 cal = new TestString1();
cal.Cal("teterhrecd");
}
}
3.
public class TestString2 {
public static void main(String args[]){
String inputStr = "teterhrecd";
HashMap hm = new HashMap();
char[] c = inputStr.toCharArray();
boolean flag = false;
for(int i = 0 ; i < c.length;i++){
for(int j = i+1; j<c.length;j++){
if(c[i]==c[j]){
flag = true;
hm.put(String.valueOf(c[i]),String.valueOf(c[i]));
break;
}
}
if(!flag && hm.get(String.valueOf(c[i]))== null){
System.out.print(c[i]);
break;
}
flag = false;
}
}
}