get All Possible Substring Combinations - Java java.lang

Java examples for java.lang:String Substring

Description

get All Possible Substring Combinations

Demo Code


//package com.java2s;

import java.util.LinkedList;

public class Main {
    public static LinkedList<String> getAllPossibleSubstringCombinations(
            String str, int maxWords) {
        LinkedList<String> ret = new LinkedList<String>();
        String partsStr[] = str.split(" ");
        for (int j = 0; j < (partsStr.length - maxWords); j++) {
            String currentStr = "";
            for (int i = 0; i < maxWords; i++) {
                currentStr += partsStr[j + i] + " ";
                ret.add(currentStr);/*w w w .ja v  a2s. c om*/
            }
        }
        return ret;
    }
}

Related Tutorials