Question: Implement a SubstringGenerator that generates all substrings of a string. For example, the substrings of the string rum are the seven strings r, ru, rum,
Implement a SubstringGenerator that generates all substrings of a string. For example, the substrings of the string "rum" are the seven strings "r", "ru", "rum", "u", "um", "m", "" Hint: First enumerate all substrings that start with the first character. There are n of them if the string has length n. Then enumerate the substrings of the string that you obtain by removing the first character.
You need to supply the following class in your solution:
SubstringGenerator
Use the following class as your tester class:
import java.util.ArrayList; import java.util.Collections; /** This program tests the substring generator. */ public class SubstringGeneratorTester { public static void main(String[] args) { SubstringGenerator generator = new SubstringGenerator("rum"); ArrayList substrings = generator.getSubstrings(); // Sort the result for checking Collections.sort(substrings); System.out.println(substrings); System.out.println("Expected: [, m, r, ru, rum, u, um]"); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
