public class removeDuplicate { public static String removeDuplicate ( String str ){ if ( str .length() <= 1 ){ return str ; } String out = removeDuplicate ( str .substring( 1 )) ; if ( str .charAt( 0 ) == str .charAt( 1 )){ return out ; } else { return str .charAt( 0 ) + out ; } } public static void main ( String [] args ) { System . out .println( removeDuplicate ( "abacd" )) ; } }