Hi i am taking common count in two list.
Here is my code.
public static int getMatchCount(List<String> listOne, List<String> listTwo) {
String valueOne = "";
String valueTwo = "";
int matchCount = 0;
boolean isMatchedOnce=false;
for (int i = 0; i < listOne.size(); i++) {
valueOne = listOne.get(i);
isMatchedOnce=false;
if (StringUtils.isBlank(valueOne))
continue;
for (int j = 0; j < listTwo.size(); j++) {
valueTwo = listTwo.get(j);
if (StringUtils.isBlank(valueTwo))
continue;
if (valueTwo.equals(valueOne) && (!isMatchedOnce)) {
matchCount++;
listOne.set(i, "");
listTwo.set(j, "");
isMatchedOnce=true;
}
}
}
return matchCount;
}
for ex
listone listTwo
A A
A B
B
Then result is 2 not 3
As their is only two common pair we can take out.
But the method is very slow Any Improvement in Above method to make it quick.
This should be an easier work around: