Java Program to find all subsets of a string8 Jan 2025 | 2 min read In this program, all the subsets of the string need to be printed. The subset of a string is the character or the group of characters that are present inside the string. All the possible subsets for a string will be n(n+1)/2. For example, all possible subsets of a string "FUN" will be F, U, N, FU, UN, FUN. To complete this program, we need to run two for loops. The outer loop is used to maintain the relative position of the first character and the second loop is used to create all possible subsets and prints them one by one. The algorithm of the program is given below. Algorithm
Program:Output: All subsets for given string are: F FU FUN U UN N Next TopicJava Programs |
Java Convert double to String We can convert double to String in java using String.valueOf() and Double.toString() methods. Scenario It is generally used if we have to display double value in textfield for GUI application because everything is displayed as a string in form. 1) String.valueOf() The String.valueOf() is an overloaded...
1 min read
Java Convert String to int We can convert String to an int in java using Integer.parseInt() method. To convert String into Integer, we can use Integer.valueOf() method which returns instance of Integer class. Scenario It is generally used if we have to perform mathematical operations on the string which...
2 min read
In this program, we will create a singly linked list and delete a node from the beginning of the list. To accomplish this task, we need to make the head pointer pointing to the immediate of the initial node which will now become the...
6 min read
Write a code to prove that strings are immutable in java? Following program demonstrate it. File: ProveStringImmutable .java public class ProveStringImmutable { public static void referenceCheck(Object x, Object y) { if (x == y) { System.out.println("Both pointing to the same reference"); } else { System.out.println("Both are pointing to different reference"); } } public static void...
1 min read
In this program, we will create a singly linked list and add a new node at the middle of the list. To accomplish this task, we will calculate the size of the list and divide it by 2 to get the mid-point of the list...
7 min read
Bubble Sort is one of the simplest sorting algorithms, primarily used for educational purposes due to its ease of implementation and understanding. Despite its simplicity, it's not the most efficient sorting algorithm for large datasets. However, comprehending Bubble Sort provides a foundational understanding of sorting...
6 min read
Program to print the elements of an array present on even position In this program, we need to print the element which is present on even position. Even positioned element can be found by traversing the array and incrementing the value of i by 2. In the...
1 min read
We can capitalize each word of a string by the help of split() and substring() methods. By the help of split("\\s") method, we can get all words in an array. To get the first character, we can use substring() or charAt() method. Let's see the example...
1 min read
In this section, we will learn how to reverse a number in Java using while loop, for loop and recursion. To reverse a number, follow the steps given below: First, we find the remainder of the given number by using the modulo (%) operator. Multiply the variable reverse...
5 min read
How to Reverse a String in Java Word by Word In this section, we reverse a string in Java word by word. Example 1: Reverse a string word by word using recursion import java.util.Scanner; public class ReverseStringExample1 { public static void main(String[] args) { String str; System.out.println("Enter a string: "); Scanner scanner =...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India