This simple Java Program generates all possible sub String of given string.You can replace string with StringBuilder or StringBuffer where performance is issue.
package com.techy.rajeev;
public class GenStr {
/**
* @param args
*/
public static void genAllSubStr(String str){
for(int i=0;i<str.length();i++){
for(int j=i;j<str.length();j++){
System.out.println(str.substring(i, j+1));
}
}
}
public static void main(String[] args) {
genAllSubStr("abc");
}
}
Output:
a
ab
abc
b
bc
c