Toggle case of a string using Bitwise Operators | program to get toggle case of a string ; tOGGLE cASE = swaps CAPS to lower case and lower case to CAPS ; Bitwise EXOR with 32 ; Driver program
public class Test { static int x = 32 ; static String toggleCase ( char [ ] a ) { for ( int i = 0 ; i < a . length ; i ++ ) { a [ i ] ^= 32 ; } return new String ( a ) ; } public static void main ( String [ ] args ) { String str = " CheRrY " ; System . out . print ( " Toggle ▁ case : ▁ " ) ; str = toggleCase ( str . toCharArray ( ) ) ; System . out . println ( str ) ; System . out . print ( " Original ▁ string : ▁ " ) ; str = toggleCase ( str . toCharArray ( ) ) ; System . out . println ( str ) ; } }