Modify array of strings by replacing characters repeating in the same or remaining strings | Java program for the above approach ; Function to remove duplicate characters across the strings ; Stores distinct characters ; Size of the array ; Stores the list of modified strings ; Traverse the array ; Stores the modified string ; Iterate over the characters of the modified string ; If character is already present ; Insert character into the Set ; Print the list of modified strings ; Print each string ; Driver Code ; Given array of strings ; Function Call to modify the given array of strings
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void removeDuplicateCharacters ( String arr [ ] ) { HashSet < Character > cset = new HashSet < > ( ) ; int n = arr . length ; ArrayList < String > out = new ArrayList < > ( ) ; for ( String str : arr ) { String out_curr = " " ; for ( char ch : str . toCharArray ( ) ) { if ( cset . contains ( ch ) ) continue ; out_curr += ch ; cset . add ( ch ) ; } if ( out_curr . length ( ) != 0 ) out . add ( out_curr ) ; } for ( int i = 0 ; i < out . size ( ) ; i ++ ) { System . out . print ( out . get ( i ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { String arr [ ] = { " Geeks " , " For " , " Geeks " , " Post " } ; removeDuplicateCharacters ( arr ) ; } }