Thursday, 15 September 2016

Comparing Two Strings Cama Separated values and avoid Duplicates values

public class StringCamaTest {
public static void main(String[] args){
String s1= "a,b,c,d,i,j,k";
String s2= "e,f,g,h";
String[] ContentFirstString  = s1.split("\\s*,\\s*");
String[] ContentSecondString = s2.split("\\s*,\\s*");
for (int i=0; i<ContentFirstString.length ;i++){
for (int j=0;j<ContentSecondString.length;j++){
if (!ContentFirstString[i]
.equalsIgnoreCase(ContentSecondString[j])) {
s1 = s1 + ","+ ContentSecondString[j];
}
}
System.out.println("s1 comapre to s2 and adding s2 values without duplicates::"+s1);
break;
}
}
}


Output:
=================
s1 comapre to s2 and adding s2 values without duplicates::a,b,c,d,i,j,k,e,f,g,h

No comments:

Post a Comment