text: Delete all odd frequency elements from an Array | Java program to removes all odd frequency elements from an Array ; Function that removes the elements which have odd frequencies in the array ; Create a map to store the frequency of each element ; Remove the elements which have odd frequencies ; If the element has odd frequency then skip ; Driver code ; Function call
code: import java . util . * ; class GFG { static void remove ( int arr [ ] , int n ) { HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . put ( arr [ i ] , 1 ) ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( ( mp . containsKey ( arr [ i ] ) && mp . get ( arr [ i ] ) % 2 == 1 ) ) continue ; System . out . print ( arr [ i ] + " , ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 3 , 3 , 2 , 2 , 4 , 7 , 7 } ; int n = arr . length ; remove ( arr , n ) ; } }