If elements of any pair are equal and their frequency is not divisible by 2 update the isArrayPossible variable to false and break through the loop
if ( m . getKey ( ) == s1 - m . getKey ( ) ) { if ( mp . get ( m . getKey ( ) ) % 2 != 0 ) { isArrayPossible = false ; break ; } }