Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Java program to generate all possible sub string of a string


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



This post first appeared on TechSoftEng, please read the originial post: here

Share the post

Java program to generate all possible sub string of a string

×

Subscribe to Techsofteng

Get updates delivered right to your inbox!

Thank you for your subscription

×