Java Program To Check Whether One String Is Rotation Of Another String
Chapter:
Interview Programs
Last Updated:
26-08-2016 14:40:27 UTC
Program:
/* ............... START ............... */
public class JavaRotationOfAnotherString {
public static void main(String[] args) {
String string1 = "JavaJ2eeStrutsHibernate";
String string2 = "StrutsHibernateJavaJ2ee";
if (string1.length() != string2.length()) {
System.out.println("string2 is not rotated version of string1");
} else {
String s3 = string1 + string1;
if (s3.contains(string2)) {
System.out.println("string2 is a rotated version of string1");
} else {
System.out.println("string2 is not rotated version of string1");
}
}
}
}
/* ............... END ............... */
Output
string2 is a rotated version of string1
Tags
One String Is Rotation Of Another String, Java, Interview Programs