Convert Collection into Array in Java

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

909 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 ...

Inorder Tree Traversal in Java

Aishwarya Naglot
Updated on 24-Jun-2025 13:15:51

1K+ Views

In-order traversal processes each node by visiting the left subtree first, then the node itself, and finally the right subtree. This is particularly useful for certain types of tree structures, such as binary search trees, where in-order traversal will print the values in sorted order. In this article, we will explore how to perform an in-order traversal of a binary tree. Following are the ways to implement in-order traversal in Java: Using Recursion Using Stack (Iteration) Inorder Tree Traversal using Recursion To traverse a tree in order using recursion, we ...

Remove All Whitespace from String in Java

Aishwarya Naglot
Updated on 24-Jun-2025 13:03:06

8K+ Views

In this article, we will learn how to remove all whitespace from a string in Java. For example, if the given string contains white spaces as shown below - Initial String = "Hi how are you Welcome to Tutorialspoint.com" The output should contain a string without white spaces as - String without whitespaces = "HihowareyouWelcometoTutorialspoint.com" Using replaceAll() Method The replaceAll() method replaces substrings that match a given regular expression with a specified string. By passing white spaces and an empty string as parameters to this method, we can remove all whitespaces from the input string. Steps to remove ...

Get Minimum and Maximum from a List in Java

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

972 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 ...

Shuffle Elements of a Collection in Java

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

302 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 ...

Remove N-th Character from a String in Python

Akshitha Mote
Updated on 23-Jun-2025 19:30:06

1K+ Views

The problem statement is to remove the nth character from the given string. Let's understand with an example. Consider my_string = "Tutorialspoint". The given value of n is 6; then we need to remove the 5th character from the string. Because the index value starts from zero. And it should result in "Tutorialspoint". Removing nth Character using a for Loop The for loop can be used to remove the n-th character from a string. In this approach, we iterate through each index of the string and print the characters. If the index value is equal to the given (n-1)th value, we ...

Get the Size of a List in Python

Akshitha Mote
Updated on 23-Jun-2025 19:20:39

5K+ Views

In Python, a list is an ordered sequence that can hold several object types, such as integers, characters, or floats. In other programming languages, a list is equivalent to an array. In this article, we need to determine the size of a list, which refers to its length. For instance, the list [10, 20, 30, 40] has a length of 4. Using 'len()' method In Python, the len() method returns the number of items in a list. Example In the following example, we have created an input list and to find the length of the list, it is passed an argument ...

Return Object from Function in Python

Akshitha Mote
Updated on 23-Jun-2025 17:33:43

15K+ Views

In Python, we can return an object from a function, using the return keyword, just like any other variable. The statements after the return will not be executed. The return keyword cannot be used outside the function. If the function has a return statement without any expression, then the special value None is returned. In the following example, the function returned the sum of two numbers - def Sum(a, b): return a+b my_var1 = 23 my_var2 = 105 result_1 = Sum(my_var1, my_var2) # function call print(result_1) Following is an output of ...

Python Program for Modular Exponentiation

Akshitha Mote
Updated on 23-Jun-2025 17:26:07

759 Views

What is Modular Exponentiation? To calculate Modular exponentiation, we need to raise a base to an exponent and then calculate the modulus of the result. This includes 3 integers: base, exponent, and modulo. Following is the syntax of the modular exponentiation in Python - (base**exponent) % modulo For instance, consider (2^5) % 5, which indicates 2 raised to the power of 5, which results in 32; When the modulo operation is performed, it returns the remainder, i.e., 32 % 5 is 3. Modular Exponentiation using Recursive Function A function that calls itself is known as a recursive function. Following is ...

Create Word Cloud Using Python

Akshitha Mote
Updated on 23-Jun-2025 17:12:23

1K+ Views

A "word cloud" is a visual representation of text data, where the size of each word indicates its frequency or importance within the dataset. It helps us to identify the most common and important words in a text. It is typically used to describe/denote big data in a word. In this article, we will create a word cloud on the Python programming language, and the data is accessed from Wikipedia. Modules to create a Word Cloud in Python Following are the modules required to create a word cloud in Python : Install wordcloud Before installing the word cloud module, you have ...

1 2 3 4 5 ... 7807 Next