Program to print all substrings of a given string | Java program to print all substrings of a string ; Function to print all substring ; Pick starting point in outer loop and lengths of different strings for a given starting point ; Driver code
public class GFG { public static void SubString ( String str , int n ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j <= n ; j ++ ) System . out . println ( str . substring ( i , j ) ) ; } public static void main ( String [ ] args ) { String str = " abcd " ; SubString ( str , str . length ( ) ) ; } }