I am trying to use an IntStream to increment an int value that is outside the stream.The point of this method is to find if there are chars on same position that are not equal. The n and word Strings are both same length.
When I try to increment the counter in the scope of forEach it shows me that it should be final or effectively final. Anyone could suggest a better way to do this or a way to increment this counter?
public boolean check(String n,String word){
int counter=0;
IntStream.range(0, n.length())
.forEach(z->{
if(n.charAt(z)!=word.charAt(z)){
counter++;
}
});
if(counter>1)
return false;
else
return true;
}