Find one extra character in a string | Java program to find extra character in one string ; result store the result ; traverse string A till end and xor with res ; xor with res ; traverse string B till end and xor with res ; xor with res ; print result at the end ; Driver code ; given string
import java . io . * ; class GFG { static char findExtraCharcter ( String strA , String strB ) { int res = 0 , i ; for ( i = 0 ; i < strA . length ( ) ; i ++ ) { res ^= strA . charAt ( i ) ; } for ( i = 0 ; i < strB . length ( ) ; i ++ ) { res ^= strB . charAt ( i ) ; } return ( ( char ) ( res ) ) ; } public static void main ( String args [ ] ) { String strA = " abcd " ; String strB = " cbdad " ; System . out . println ( findExtraCharcter ( strA , strB ) ) ; } }