Answers for "all possible substrings of a string java"

1

find all possible substrings of a string java

for (int i = 0; i < A.length(); i++) {
    for (int j = i+1; j <= A.length(); j++) {
        System.out.println(A.substring(i,j));
    }
}
Posted by: Guest on April-12-2021
0

Create all possible substrings of a string java

public int delete(String query, HashSet dictionary) {
    Queue queue = new LinkedList();
    Set queueElements = new HashSet();
 
    queue.add(query);
    queueElements.add(query);
 
    while (!queue.isEmpty()) {
        String s = queue.remove();
        queueElements.remove(s);
        if (dictionary.contains(s)) return query.length() - s.length();
 
        for (int i = 0; i < s.length(); i++) { String sub = s.substring(0, i) + s.substring(i+1, s.length()); if (sub.length() > 0 && !queueElements.contains(sub)) {
                // this for loop creates all possible substrings
                queue.add(sub);
                queueElements.add(sub);
            }
        }
    }
    return -1;
}
Posted by: Guest on January-26-2022

Code answers related to "all possible substrings of a string java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language