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