Check if a string can be split into two substrings such that one substring is a substring of the other | Java program to implement the above approach ; Function to check if a String can be divided into two subStrings such that one subString is subString of the other ; Store the last character of S ; Traverse the characters at indices [ 0 , N - 2 ] ; Check if the current character is equal to the last character ; If true , set f = 1 ; Break out of the loop ; Driver Code ; Given String , S ; Store the size of S ; Function Call
import java . util . * ; class GFG { static void splitString ( String S , int N ) { char c = S . charAt ( N - 1 ) ; int f = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( S . charAt ( i ) == c ) { f = 1 ; break ; } } if ( f > 0 ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } public static void main ( String [ ] args ) { String S = " abcdab " ; int N = S . length ( ) ; splitString ( S , N ) ; } }