Found 33676 Articles for Programming

Java program to convert a list of string to comma separated string

Aishwarya Naglot
Updated on 26-Aug-2025 16:44:22

808 Views

A list is a collection in Java which is used for storing group of elements. It is an ordered collection which also allows to store duplicate elements. A String is a sequence of characters which is used for representing text in Java. Here, in this article, we are given a list of strings, we have to convert it into a comma-separated string in Java using different approaches. To understand this problem, consider the following input-output scenarios: Scenario 1 Input: ["Apple", "Banana", "Mango", "Orange"] Output: Apple, Banana, Mango, Orange Scenario 2 Input: ["Red", "Green", "Blue"] Output: ... Read More

Java Program to Differentiate String == operator and equals() method

Revathi Satya Kondra
Updated on 06-Jan-2025 22:46:56

299 Views

In this article, we will understand how to differentiate == operator and equals() method in Java. The == (equal to) operator checks if the values of two operands are equal or not, if yes then the condition becomes true. The equals() method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object. Below is a demonstration of the same − Suppose our input is − The first string: abcde The second string: 12345 The ... Read More

Java Program to Remove a Sublist from a List

AmitDiwan
Updated on 29-Mar-2022 12:28:04

423 Views

In this article, we will understand how to remove a sub-list 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 the duplicate elements.Below is a demonstration of the same −Suppose our input is −Input list: [Java, Programming, Is, Fun]The desired output would be −The list after removing a sublist is: [Java, Programming]AlgorithmStep 1 - START Step 2 - Declare an AbstractList namely input_list. Step 3 - Add the values to the list. Step 4 ... Read More

Java program to iterate through each character of the string.

AmitDiwan
Updated on 29-Sep-2024 02:48:31

2K+ Views

In this article, we will understand how to iterate through each character of the string using Java. The string is a datatype that contains one or more characters and is enclosed in double quotes (“ ”). Char is a datatype that contains an alphabet an integer or a special character. Problem Statement Write a program to Iterate through each character of the string. Below is a demonstration of the same − Input The string is defined as: Java Program Output The characters in the string are: J, a, v, a, , P, r, o, g, r, a, m, Different approaches ... Read More

Java Program to Capitalize the first character of each word in a String

AmitDiwan
Updated on 31-May-2024 16:49:35

10K+ Views

A string is a class of 'java.lang' package that stores a series of characters. Those characters are actually String-type objects. We must enclose the value of string within double quotes. Generally, we can represent characters in lowercase and uppercase in Java. And, it is also possible to convert lowercase characters into uppercase. This article aims to discuss a Java program to convert the first character of each word into uppercase in a string. Java program to Capitalize the first character of each word in a String Before making a Java program to convert the first lowercase character of a ... Read More

Java Program to Clear the StringBuffer

Shriansh Kumar
Updated on 16-Aug-2024 07:36:08

2K+ Views

On clearing the StringBuffer object, all the characters from the buffer will be removed. In this article, we will write Java program to clear the StringBuffer. StringBuffer is a peer class of String that provides much of the functionality of strings. But, String represents fixed-length, immutable character sequences while StringBuffer represents mutable character sequences. Example Scenario: Input: obj = Java Program Output: res = The result will be an empty StringBuffer object. Using delete() method The StringBuffer class of java.lang package provides a method named delete() to clear the StringBuffer. This method accepts start and end indices ... Read More

Java Program to Create random strings

AmitDiwan
Updated on 29-Mar-2022 12:18:27

749 Views

In this article, we will understand how to create random strings. 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 −The size of the string is defined as: 10The desired output would be −Random string: ink1n1dodvAlgorithmStep 1 - START Step 2 - Declare an integer namely string_size, a string namely alpha_numeric and an object of StringBuilder namely string_builder. Step 3 - Define the values. Step 4 - Iterate for 10 times usinf a for-loop, generate a random value using the function Math.random() ... Read More

Java program to split a list into two halves

AmitDiwan
Updated on 27-Aug-2024 18:48:06

2K+ Views

In this article, we will understand how to split a list into two halves. A 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. We will be using different approaches to split a list into two halves − Problem Statement Write a Java program to split a list into two halves. As demonstrated below − Input  Input list :[Java, Python, JavaScript, Shell, Scala] Output The first half of the list is: [Java, Python] The second half of ... Read More

C++ code to count days to complete reading book

Arnab Chakraborty
Updated on 29-Mar-2022 12:18:41

319 Views

Suppose we have an array A with n elements and have another value t. On ith day Amal spends A[i] seconds in work. In the free time he reads a book. The entire book will take t seconds to complete. We have to find how many days he will need to read the complete book.So, if the input is like A = [86400, 86398]; t = 2, then the output will be 2, because one day has 86400 seconds, and first day is totally blocked. On second day he will get 2 seconds to complete the book.StepsTo solve this, we ... Read More

Java Program to split into a number of sub-strings

AmitDiwan
Updated on 29-Mar-2022 12:09:04

679 Views

In this article, we will understand how to splitting into a number of sub-strings. 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 −Input string: JVMThe desired output would be −The substring list printed as an ArrayList : [J, JV, JVM, V, VM, M] The sub-strings after splitting is: (1) "J" (2) "JV" (3) "JVM" (4) "V" (5) "VM" (6) "M"AlgorithmStep 1 - START Step 2 - Declare a string namely ... Read More

Advertisements