Check if the element exists in the map
if ( mp . get ( s1 ) >= 2 ) { mp . replace ( s1 , mp . get ( s1 ) - 2 ) ; } else { isArrayPossible = false ; } if ( isArrayPossible ) { for ( Map . Entry < Integer , Integer > m : mp . entrySet ( ) ) {