Check if characters of a given string can be rearranged to form a palindrome | Java Implementation of the above approach ; bitvector to store the record of which character appear odd and even number of times ; Driver Code
import java . io . * ; class GFG { static boolean canFormPalindrome ( String a ) { int bitvector = 0 , mask = 0 ; for ( int i = 0 ; i < a . length ( ) ; i ++ ) { int x = a . charAt ( i ) - ' a ' ; mask = 1 << x ; bitvector = bitvector ^ mask ; } return ( bitvector & ( bitvector - 1 ) ) == 0 ; } public static void main ( String [ ] args ) { if ( canFormPalindrome ( " geeksforgeeks " ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }