0

I need to do some complex work on all substrings of the given string, for which I need to find all substrings of the given string. I am wondering if it is possible to do without nested loops (n^2 complexity)?

Any other suggestions on optimizing this?

int originalStringlength = str.length();
for(int start = 0 ; start < originalStringlength ; start++){
   for(int chars = 1; chars <= originalStringlength - start; chars++){
      String substr = str.substring(start, start+chars);
      System.out.prinln("Substring: " +  substr);
    //do further processing
   }    
}
Andy Turner
  • 122,430
  • 10
  • 138
  • 216
Manish
  • 1,355
  • 2
  • 14
  • 27

0 Answers0