
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Print all subsequences of a string using ArrayList in C++
In this problem, we are given a string and we have to print all subsequences of the string. The substring is formed by deleting elements. Also, the order of string should not be altered.
Let’s take an example to understand the problem better −
Input: string = “xyz” Output: x y xy z xz yz xyz
To solve this problem, we will find all substring starting from freezing the first character of the string and find subsequence accordingly, then going for the next character in string and subsequence.
Example
public class Main { public static void printSubString(String sub,String subSeq){ if (sub.length() == 0) { System.out.print(subSeq+" "); return; } char ch = sub.charAt(0); String ros = sub.substring(1); printSubString(ros, subSeq); printSubString(ros, subSeq + ch); } public static void main(String[] args){ String str = "wxyz"; System.out.println("The subStrings are :"); printSubString(str, ""); } }
Output
The subStrings are −
z y yz x xz xy xyz w wz wy wyz wx wxz wxy wxyz
- Related Articles
- Print all subsequences of a string in C++
- Print all subsequences of a string using Iterative Method in C++
- Print all permutation of a string using ArrayList in Java
- Print all Subsequences of String which Start with Vowel and End with Consonant in C++
- Print all permutations of a string in Java
- Print all permutations of a given string
- Print all palindromic partitions of a string in C++
- Print all palindrome permutations of a string in C++
- How to print all the characters of a string using regular expression in Java?
- Python Program to Print All Permutations of a String in Lexicographic Order using Recursion
- Print all distinct characters of a string in order in C++
- Print all funny words in a string in C++
- Program to print all substrings of a given string in C++
- Count all increasing subsequences in C++
- Print all the combinations of a string in lexicographical order in C++

Advertisements