Found 2616 Articles for Java

Java Program To Find all the Subsets of a String

AmitDiwan
Updated on 30-Mar-2022 07:21:35

998 Views

In this article, we will understand how to find all the subsets of a string. 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.Below is a demonstration of the same −Suppose our input is −The string is defined as: JVMThe desired output would be −The subsets of the string are: J JV JVM V VM MAlgorithmStep 1 - START Step 2 - Declare namely Step 3 - Define the values. Step 4 - Initialize a temporary variable to increment after every iteration. ... Read More

Java Program to divide a string in 'N' equal parts

AmitDiwan
Updated on 30-Mar-2022 07:07:44

507 Views

In this article, we will understand how to divide a string in 'N' equal parts. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”).Below is a demonstration of the same −Suppose our input is −Input string: Java Program is fun!The desired output would be −The length of the string is: 20 4 equal parts of given string are Java Progr am is fun!AlgorithmStep 1 - START Step 2 - Declare a string namely input_string, two integers namely string_length and N. Step 3 - Define the values. Step 4 - Initiatize a temporary ... Read More

Java Program to Get Minimum and Maximum From a List

AmitDiwan
Updated on 30-Mar-2022 06:57:32

553 Views

In this article, we will understand how to get minimum and maximum from a list. A list is an ordered collection that allows us to store and access elements sequentially. It contains the index-based methods to insert, update, delete and search the elements. It can also have duplicate elements.Below is a demonstration of the same −Suppose our input is −Input list: [500, 650, 300, 250, 110]The desired output would be −The minimum value of the list is: 110 The maximum value of the list is: 650AlgorithmStep 1 - START Step 2 - Declare a list namely input_list. Step 3 - ... Read More

Java Program to Check if a String is Empty or Null

AmitDiwan
Updated on 30-Mar-2022 06:53:24

690 Views

In this article, we will understand how to check if a string is empty or null. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”).Below is a demonstration of the same −Suppose our input is −Input string: nullThe desired output would be −The string is a null stringAlgorithmStep 1 - START Step 2 - Declare a string namely input_string. Step 3 - Define the values. Step 4 - Using an if-loop, compute input_string == null. If true, the string is null, else the string is not null. Step 5 - Display the ... Read More

Java Program to Remove All Whitespaces from a String

AmitDiwan
Updated on 30-Mar-2022 06:49:04

248 Views

In this article, we will understand how to remove all whitespaces from a string. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”).Below is a demonstration of the same −Suppose our input is −Input string: Java programming is fun to learn.The desired output would be −The string after replacing white spaces: Javaprogrammingisfuntolearn.AlgorithmStep 1 - START Step 2 - Declare two strings namely String input_string and result. Step 3 - Define the values. Step 4 - Use the function replaceAll("\s", "") to replaces all the white spaces with blank spaces. Step 5 - ... Read More

Java Program to Convert Array into Collection

AmitDiwan
Updated on 19-Jan-2024 14:51:03

329 Views

In this article, we will understand how to convert array into collection. 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.Below is a demonstration of the same −Suppose our input is −Input array: [Java, Python, Scala, Shell]The desired output would be −After elements after converting the array to a list are: [Java, Python, Scala, Shell]AlgorithmStep 1 - START Step 2 - Declare a string array namely input_array and a list namely result_list. ... Read More

Java Program to Convert Collection into Array

AmitDiwan
Updated on 30-Mar-2022 06:40:37

496 Views

In this article, we will understand how to convert collection into array. 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.Below is a demonstration of the same −Suppose our input is −Input list: [Java , program , is , fun]The desired output would be −The result after converting to an array is: Java program is funAlgorithmStep 1 - START Step 2 - Declare a list namely input_list, a string array namely result_string. ... Read More

Java Program to Check if a string contains a substring

AmitDiwan
Updated on 10-Aug-2023 12:27:57

2K+ Views

A string is a class in Java that stores a series of characters enclosed within double quotes and a continuous sequence of characters within that string is termed as substring. Those characters are actually String-type objects. This article aims to write Java programs to check if a string contains a substring or not. To check whether the given string contains a substring or not, we can use indexOf(), contains() and substring() methods along with conditional blocks. Java Program to Check if a String Contains a Substring We are going to use the following built-in methods in our Java programs to ... Read More

Java Program to Shuffle the Elements of a Collection

AmitDiwan
Updated on 30-Mar-2022 06:34:13

199 Views

In this article, we will understand how to shuffle the elements of a collection. 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.Below is a demonstration of the same −Suppose our input is −Input list: [Java, program, is, fun, and, easy]The desired output would be −The shuffled list is: [is, easy, program, and, fun, Java]AlgorithmStep 1 - START Step 2 - Declare an arraylist namely input_list. Step 3 - Define the values. ... Read More

Java Program to Format time in AM-PM format

AmitDiwan
Updated on 30-Mar-2022 06:36:20

1K+ Views

In this article, we will understand how to format time in AM-PM format. A formatting string describes how a date/time values should be read and written from(to) string representation (flat files, human readable output, etc.)Below is a demonstration of the same −Suppose our input is −Current date: Thu Mar 17 16:04:31 IST 2022The desired output would be −The current Time in AM/PM format is : 04.04 pmAlgorithmStep 1 - START Step 2 - Declare a date object namely current_date that fetches the current date and time. Step 3 - Define the values. Step 4 - Declare an object ‘formatTime’ of ... Read More

Advertisements