Find all subsets of a string in Java

A subset of a string is a set of characters that can be obtained by selecting some or all of the characters from the original string, in any order, without repeating any characters.

Here is a Java program that finds all subsets of a string:

import java.util.*;

public class SubsetsOfString {
    public static void main(String[] args) {
        Scanner sc = new Scanner(;
        System.out.print("Enter a string: ");
        String str = sc.nextLine();
        System.out.println("Subsets of the string:");
    public static void findSubsets(String str) {
        int n = str.length();
        int total = (int) Math.pow(2, n);
        for (int i = 0; i < total; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < n; j++) {
                if ((i & (1 << j)) > 0) {

This program uses bitwise operations to generate all possible combinations of characters from the input string. It takes an input string from the user, and then generates all possible subsets of the string and prints them to the console.