public static String concatConsistentCase ( String baseString , String addition ) { boolean hasLowerCase = hasLowerCase ( baseString ) ; boolean hasUpperCase = hasUpperCase ( baseString ) ; if ( ( hasLowerCase && hasUpperCase ) || ( ! hasLowerCase && ! hasUpperCase ) ) { //mixed case || no letters return baseString + addition ; } else if ( hasLowerCase ) { return baseString + addition . toLowerCase ( ) ; } else { return baseString + addition . toUpperCase ( ) ; } }
Concatenates the addition string to the baseString string adjusting the case of addition to match the base string . If the string is all caps append addition in all caps . If all lower case append in all lower case . If baseString is mixed case make no changes to addition .