Remove duplicates from a given string | Java program to remove duplicate character from character array and print in sorted order ; Create a set using String characters excluding ' \0' ; HashSet doesn 't allow repetition of elements ; Driver code
import java . util . * ; class GFG { static void removeDuplicate ( char str [ ] , int n ) { HashSet < Character > s = new LinkedHashSet < > ( n - 1 ) ; for ( char x : str ) s . add ( x ) ; for ( char x : s ) System . out . print ( x ) ; } public static void main ( String [ ] args ) { char str [ ] = " geeksforgeeks " . toCharArray ( ) ; int n = str . length ; removeDuplicate ( str , n ) ; } }