Store all characters of anotherStr in a direct index table for quick lookup .
boolean illegal [ ] = new boolean [ MAX_CHAR ] ; for ( int i = 0 ; i < anotherStr . length ( ) ; i ++ ) { illegal [ anotherStr . charAt ( i ) ] = true ; }