应用场景: 获取两个字符串所有公共的子串。
思路: 1. 先获取两个子串的交集
2. 遍历交集子串,从最短子串到最长子串
public static List<String> getAllCommonSubStrings(String str1, String str2) {
//TODO null check.
String longString = str1;
String shortString = str2;
if(str1.length() < str2.length()){
longString = str2;
shortString = str1;
}
List<String> result = new ArrayList<String>();
List<String> vacancy = new ArrayList<String>();
vacancy.add("");
List<String> list1 = Arrays.asList(shortString.split(""));
List<String> list2 = Arrays.asList(longString.split(""));
result.addAll(list1);
result.retainAll(list2);
result.removeAll(vacancy);
List<Stri