Java String Find findAllSubsequences(String str)

Here you can find the source of findAllSubsequences(String str)

Description

find All Subsequences

License

Open Source License

Parameter

Parameter Description
str a parameter

Declaration

public static Set<String> findAllSubsequences(String str) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    /**//from   w  w  w  .j av a 2s.  c  o  m
     *
     * @param str
     * @return
     */
    public static Set<String> findAllSubsequences(String str) {
        if (str.equals("")) {
            Set<String> subsequences = new HashSet<>();
            subsequences.add(str);
            return subsequences;
        }
        Set<String> subsequences = new HashSet<>();
        char current = str.charAt(0);
        str = new StringBuilder(str).deleteCharAt(0).toString();
        Set<String> childSubsequences = findAllSubsequences(str);
        for (String subsequence : childSubsequences) {
            StringBuilder newSequence = new StringBuilder();
            newSequence.append(current);
            newSequence.append(subsequence);
            subsequences.add(newSequence.toString());
        }
        subsequences.addAll(childSubsequences);
        return subsequences;
    }
}

Related

  1. findAll(final String s, final String subs)
  2. findAll(String toSearch, String toFind, boolean ignoreCase)
  3. findAllIndexes(String str, String searchStr)
  4. findAllOccurences(String str, String pattern)
  5. findAllOccurrences(String str, String substr)
  6. findParam(String src, char patternFrom, char patternTo)
  7. findResourceBundle(String aBundleName, Locale locale)
  8. getAllOccurences(String str, char guess)
  9. getOccurenceIndices(String inSubject, String inOccurence)