Contiguous unique substrings with the given length L | Java implementation of above approach ; Function to print the unique sub - String of length n ; set to store the Strings ; if the size of the String is equal to 1 then insert ; inserting unique sub - String of length L ; Printing the set of Strings ; Driver Code ; Function calling
import java . util . * ; class GFG { static void result ( String s , int n ) { HashSet < String > st = new HashSet < String > ( ) ; for ( int i = 0 ; i < ( int ) s . length ( ) ; i ++ ) { String ans = " " ; for ( int j = i ; j < ( int ) s . length ( ) ; j ++ ) { ans += s . charAt ( j ) ; if ( ans . length ( ) == n ) { st . add ( ans ) ; break ; } } } for ( String it : st ) System . out . print ( it + " ▁ " ) ; } public static void main ( String [ ] args ) { String s = " abca " ; int n = 3 ; result ( s , n ) ; } }