首页 > 代码库 > 交集去重

交集去重

public class jiaoji {

/**
* @param args
*/
public static void main(String[] args) {
String s1="abc";
String s2="abdgca";
System.out.println(quchong(jiaoji(s1,s2)));
}
//jiaoji
static String jiaoji(String s1,String s2){
String s3="";

for (int i = 0; i < s2.length(); i++) {
int index=s1.indexOf(s2.charAt(i));
if (index>=0) {
s3+=s2.charAt(i);

}
}

return s3;

}
//quchong
static String quchong(String str){
String str1 ="";
char[] ch=str.toCharArray();
for (int i = 0; i < str.length(); i++) {

if (str1.indexOf(ch[i])==-1) {
str1+=ch[i];
}

}
return str1;
}

}

交集去重