Server Side Programming Articles - Page 517 of 2650

Java Program To Find all the Subsets of a String

Shriansh Kumar
Updated on 01-Aug-2024 10:58:32

2K+ Views

In this article, we will understand how to find all the subsets of a string. In Java, String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”). A part or a subset of string is called substring. Example Scenario: Input: string = JVM; Output: The subsets of the string are: J, JV, JVM, V, VM, M Finding all Subsets of a String in Java Use the following approaches to find all subsets of a String in Java − Using nested for Loop ... Read More

Java program to divide a string in \\'N\\' equal parts

Alshifa Hasnain
Updated on 23-Oct-2024 17:32:12

849 Views

In this article, we will understand how to divide a string into 'N' equal parts using Java. If the string's length is divisible by N, the string will be split evenly into N parts; otherwise, a message will be displayed indicating that the string cannot be divided into N equal parts. This is demonstrated using both a simple main method and an encapsulated approach. Problem Statement Write a program in Java to divide a string into 'N' equal parts. Below is a demonstration of the same − Input Input string: Java Program is fun! Output The length of the string ... Read More

Java program to get minimum and maximum from a list

Aishwarya Naglot
Updated on 24-Jun-2025 12:51:19

1K+ Views

Minimum and Maximum Values of a ListA list is an ordered collection that allows us to store and access elements sequentially. It contains index-based methods to insert, update, delete, and search the elements. It can also have duplicate elements. The following are the ways to get the minimum and maximum from a list in Java: Using Loops Using Collections Using Streams Minimum and Maximum of a List Using LoopsWe can find the minimum and maximum values in a list by iterating through the elements using loops. We will initialize two variables to save the minimum and maximum values, and ... Read More

Java program to check if a string is empty or null

AmitDiwan
Updated on 08-Nov-2024 22:31:26

1K+ Views

In this article, we will understand how to check if a string is empty or null in Java. The string is a datatype that contains one or more characters and is enclosed in double quotes(“ ”). We’ll start by learning to detect these cases directly within the main method, and then we’ll see how to achieve the same result using encapsulation for better code organization and reusability. Problem Statement Write a program in Java to check if a string is empty or null. Below is a demonstration of the same − Input Input string: null Output The string is a null ... Read More

Java program to remove all whitespaces from a string

AmitDiwan
Updated on 07-Nov-2024 01:05:37

408 Views

In this article, we will understand how to remove all whitespaces from a string in Java. The String class in Java represents a sequence of characters enclosed in double-quotes. Removing whitespaces from a string is a common operation, especially when processing user input or cleaning data. The replaceAll() method is used with a regular expression to match whitespace characters and replace them with an empty string. Problem StatementGiven a string with whitespaces, write a Java program to remove all whitespaces from the string.Input Initial String = "Java programming is fun to learn."Output String after removing white spaces = ... Read More

Java program to convert collection into array

Aishwarya Naglot
Updated on 24-Jun-2025 13:23:12

1K+ Views

The Collection is a framework that provides architecture to store and manipulate a group of objects. Java Collections can achieve all the operations that you perform on data, such as searching, sorting, insertion, manipulation, and deletion. In this article, we will understand how to convert a collection into an array in Java. Following are the ways to convert a collection into an array in Java: Using Iteration Using toArray() Method Using Streams Collection to Array using Iteration The naive way to convert a collection into an array is by traversing the collection and adding each element in the ... Read More

Java Program to Shuffle the Elements of a Collection

Aishwarya Naglot
Updated on 24-Jun-2025 12:37:37

411 Views

The Collection is a framework that provides an architecture to store and manipulate a group of objects. In Java, Collections can perform all the operations that you perform on data, such as searching, sorting, insertion, manipulation, and deletion. In this article, we will learn how to shuffle the elements of a collection in Java. Shuffling refers to randomly rearranging the elements of a collection. Let's take an example as follows: Input: list: [Java, program, is, fun, and, easy] Output: list: [fun, easy, Java, program, and, is] Ways to Shuffle Elements of a Collection in Java ... Read More

Java Program to Get the Size of the Collection

Aishwarya Naglot
Updated on 21-Aug-2025 12:32:32

218 Views

The Collection is a framework that provides architecture to store and manipulate the group of objects. Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion. In this article we will look at how to get the size of a collection in Java. The size of a collection is the number of elements it contains. Following are the ways to get the size of a collection in Java: Using size() Method Using loops Using Streams API Getting Size of Collection Using size() Method The size() method is ... Read More

Java program to compare elements in a collection

Aishwarya Naglot
Updated on 26-Aug-2025 17:18:53

830 Views

In Java, the Collection framework provides an architecture to store and manipulate a group of objects. Collections support operations such as searching, sorting, insertion, manipulation, and deletion. In this article, we will learn how to compare elements in a collection in Java using different approaches. Before learning about the methods, let us understand the problem with the help of the following input-output scenarios: Scenario 1 Input: ["Java", "Python", "JavaScript", "C++"] Element to Compare: "Java" Output: Java is equal to Java Python is not equal to Java JavaScript is not equal to Java C++ is not equal to ... Read More

Java program to print a collection

AmitDiwan
Updated on 20-Sep-2024 21:42:34

937 Views

In this article, we will understand how to print a collection in Java. The Collection is a framework that provides architecture to store and manipulate the group of objects. Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion. Problem Statement Write a program in Java to print a Collection. Below is a demonstration of the same − Input  Run the program Output The Elements of the collection are: Language : Java | Language_id : 101 Language : Scala | Language_id : 102 Language : Python | Language_id : ... Read More

Advertisements