Found 2616 Articles for Java

Java Program to Get the Size of the Collection

AmitDiwan
Updated on 30-Mar-2022 06:31:33

108 Views

In this article, we will understand how to get the size of the 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: [100, 180, 250, 300]The desired output would be −The size of the list = 4AlgorithmStep 1 - START Step 2 - Declare a list namely input_list. Step 3 - Define the values. Step 4 - Using the ... Read More

Java Program to Convert a String into the InputStream

AmitDiwan
Updated on 10-Aug-2023 13:04:15

1K+ Views

While displaying a long input string, we are sometimes required to process them in smaller units. At that time, converting that string into the InputStream will be helpful. To convert a given string into the InputStream, Java provides ByteArrayInputStream class that is used along with a built method named getBytes(). In this article, we will learn how we can use the ByteArrayInputStream class to convert a string into an InputStream with the help of example programs. Java Program to Convert a String into the InputStream This section will introduce a few concepts that will help us to understand the Java ... Read More

Java Program to Compare Elements in a Collection

AmitDiwan
Updated on 30-Mar-2022 06:28:30

551 Views

In this article, we will understand how to compare elements in 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: [300, 500, 180, 450, 610]The desired output would be −Min value of our list : 180 Max value of our list : 610AlgorithmStep 1 - START Step 2 - Declare a list namely input_list Step 3 - Define ... Read More

Java Program to Print a Collection

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

588 Views

In this article, we will understand how to print 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 −Run the programThe desired output would be −The Elements of the collection are: Language : Java | Language_id : 101 Language : Scala | Language_id : 102 Language : Python | Language_id : 103 Language : Mysql | Language_id : 104AlgorithmStep 1 ... Read More

Java Program to Lookup enum by String value

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

622 Views

In this article, we will understand how to lookup enum by string value. An enum is a special "class" that represents a group of constants (unchangeable variables, like final variables).Below is a demonstration of the same −Suppose our input is −The string is to lookup is: JavaThe desired output would be −The result is: JAVAAlgorithmStep 1 - START Step 2 - Declare a string namely input_string, an object of Languages namely result. Step 3 - Define the values. Step 4 - Use the function .valueOf() to fetch the string from the enum function. Step 5 - Display the result Step ... Read More

Java Program to Implement switch statement on strings

AmitDiwan
Updated on 30-Mar-2022 06:08:59

170 Views

In this article, we will understand how to implement switch statement on strings. The switch expression is evaluated once. The value of the expression is compared with the values of each case. 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: JavaThe desired output would be −Using siwtch cases: We shall use Java for our codingAlgorithmStep 1 - START Step 2 - Declare a string namely input_string. Step 3 - Define the values. Step 4 - Define a stwtch statement ... Read More

Java Program to Replace the Spaces of a String with a Specific Character

AmitDiwan
Updated on 30-Mar-2022 05:49:41

867 Views

In this article, we will understand how to replace the spaces of a string with a specific character. 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 to learn Input character: $The desired output would be −The string after replacing spaces with given character is: Java$Program$is$fun$to$learnAlgorithmStep 1 - START Step 2 - Declare a string namely input_string, a char namely input_character. Step 3 - Define the values. Step 4 - Using the function replace(), replace the ... Read More

Java Program to Join Two Lists

AmitDiwan
Updated on 29-Mar-2022 13:50:24

243 Views

In this article, we will understand how to join two lists. The ArrayList class extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as needed.Array lists are created with an initial size. When this size is exceeded, the collection is automatically enlarged. When objects are removed, the array may be shrunk.Below is a demonstration of the same −Suppose our input is −First list is defined as: [Java, Python] Second list: [Mysql, Redshift]The desired output would be −The list after joining two strings: [Java, Python, Mysql, Redshift]AlgorithmStep 1 - START Step 2 - Declare two lists ... Read More

Java Program to Access elements from a LinkedList

AmitDiwan
Updated on 29-Mar-2022 12:54:08

317 Views

In this article, we will understand how to access elements from a linked-list. The java.util.LinkedList class operations perform we can expect for a doubly-linked list. Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.Below is a demonstration of the same −Suppose our input is −Input list: [Python, Java, Scala, Java, JavaScript]The desired output would be −The element at index 3 is: JavaAlgorithmStep 1 - START Step 2 - Declare a linked list namely input_list. Step 3 - Define the values. Step 4 - Using the built-in ... Read More

Java Program to Add elements to a LinkedList

AmitDiwan
Updated on 10-Aug-2023 12:14:07

253 Views

LinkedList is a generic class of Java Collection Framework that implements three interfaces namely List, Deque, and Queue. It provides the features of a LinkedList data structure which is a linear data structure where each element are linked with each other. There are several operations we can perform on LinkedList including appending, removing and traversing of elements. To add elements to a LinkedList Collection we can use various built-in methods such as add(), addFirst() and addLast(). We are going to explore how we can use these methods to add elements to a LinkedList. Adding elements to a LinkedList in Java ... Read More

Advertisements