Check Concatenation of Substrings
This program checks if string is concatenation of given substrings.
Problem Statement
Write a Java program to check if "EduinqEduinq" is concatenation of "Eduinq".
Source Code
| 1 | public class SubstringConcatenationCheck { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Substring Concatenation Check"); |
| 4 | String str="EduinqEduinq", sub="Eduinq"; |
| 5 | if(str.length()%sub.length()==0 && str.replace(sub,"").isEmpty()) |
| 6 | System.out.println("String is concatenation of substring"); |
| 7 | else System.out.println("Not concatenation"); |
| 8 | } |
| 9 | } |
Program Output
Eduinq Substring Concatenation Check String is concatenation of substring
Explanation
The string's length must be evenly divisible by the substring's length, and replacing all occurrences of the substring should leave an empty result, together confirming that the string is a pure concatenation of the substring.