Check if a string is suffix of another | Java program to find if a string is suffix of another ; Driver code ; Test case - sensitive implementation of endsWith function
class GFG { static boolean isSuffix ( String s1 , String s2 ) { int n1 = s1 . length ( ) , n2 = s2 . length ( ) ; if ( n1 > n2 ) return false ; for ( int i = 0 ; i < n1 ; i ++ ) if ( s1 . charAt ( n1 - i - 1 ) != s2 . charAt ( n2 - i - 1 ) ) return false ; return true ; } public static void main ( String [ ] args ) { String s1 = " geeks " , s2 = " geeksforgeeks " ; boolean result = isSuffix ( s1 , s2 ) ; if ( result ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }