Generate all rotations of a given string | A simple Java program to generate all rotations of a given string ; Print all the rotated string . ; Concatenate str with itself ; Print all substrings of size n . Note that size of sb is 2 n ; Driver method
class Test { static void printRotatedString ( String str ) { int n = str . length ( ) ; StringBuffer sb = new StringBuffer ( str ) ; sb . append ( str ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j != n ; j ++ ) System . out . print ( sb . charAt ( i + j ) ) ; System . out . println ( ) ; } } public static void main ( String [ ] args ) { String str = new String ( " geeks " ) ; printRotatedString ( str ) ; } }