Find if an array contains a string with one mismatch | Java program to find if given string is present with one mismatch . ; If the array is empty ; If sizes are same ; If first mismatch ; Second mismatch ; Driver code
import java . util . * ; class GFG { static boolean check ( Vector < String > list , String s ) { int n = ( int ) list . size ( ) ; if ( n == 0 ) { return false ; } for ( int i = 0 ; i < n ; i ++ ) { if ( list . get ( i ) . length ( ) != s . length ( ) ) { continue ; } boolean diff = false ; for ( int j = 0 ; j < ( int ) list . get ( i ) . length ( ) ; j ++ ) { if ( list . get ( i ) . charAt ( j ) != s . charAt ( j ) ) { if ( ! diff ) { diff = true ; } else { diff = false ; break ; } } } if ( diff ) { return true ; } } return false ; } public static void main ( String [ ] args ) { Vector < String > s = new Vector < > ( ) ; s . add ( " bana " ) ; s . add ( " apple " ) ; s . add ( " banacb " ) ; s . add ( " bonanza " ) ; s . add ( " banamf " ) ; System . out . println ( check ( s , " banana " ) == true ? 1 : 0 ) ; } }