How do you turn an ArrayList into a Set in Java?

Aishwarya Naglot
Updated on 30-May-2025 18:10:34

11K+ Views

In this article, let's learn how to convert an ArrayList into a Set in Java. ArrayList is a collection that allows us to store duplicates, whereas Set is a collection that does not allow duplicates. So, when we convert an ArrayList to a Set, all the duplicate elements will be removed. If someone tries to add duplicate elements to a Set, it will not throw an error but will simply ignore the duplicate elements. Let's take an example: Input: [1, 2, 3, 4, 5, 5, 6] Output: [1, 2, 3, 4, 5, 6] Ways to Convert an ArrayList to ... Read More

How to check if input is numeric in C++?

Nishu Kumari
Updated on 30-May-2025 18:07:17

6K+ Views

Numeric input means a value that contains only digits from 0 to 9, without any letters or special characters. In this article, we'll show you how to write a C++ program to check whether the input is numeric. Let's understand this with a few examples: //Example 1: Input: 12345 Output: Valid numeric input //Example 2: Input: 12a5 Output: Not a numeric input We will cover two common ways to check if the input is numeric or not in C++. Using std::getline with std::isdigit Check Using stringstream to Parse ... Read More

How to find the size of an int[] in C/C++?

Nishu Kumari
Updated on 30-May-2025 18:05:34

8K+ Views

In C and C++, arrays can store multiple values of the same data type. This problem is about finding how many elements are present in a statically declared int[] array (not pointers or dynamically allocated arrays). We'll learn how to find the size of an int[] in both C and C++. Let's understand this with an example: //Example 1 input: int numbers[] = {10, 20, 30, 40, 50}; This array has 5 elements. Output: Number of elements: 5 //Example 2: Input: int values[] = {1, 2, 3}; This array has 3 elements. Output: Number of elements: 3 ... Read More

C++ Program to Check if a Matrix is Invertible

Nishu Kumari
Updated on 30-May-2025 18:04:19

411 Views

A matrix is invertible if it has an inverse. An inverse of a matrix exists only when its determinant is non-zero. If the determinant of a matrix is zero, the matrix is called singular and cannot be inverted. In this article, we'll write a C++ program to check if a matrix is invertible using its determinant. To better understand this, let's take the following 3x3 matrix as an example: Given 3*3 Matrix: 4 2 1 2 1 1 9 3 2 To check if this matrix is invertible, we ... Read More

C++ Program to Perform LU Decomposition of any Matrix

Nishu Kumari
Updated on 30-May-2025 18:02:25

5K+ Views

The LU decomposition of a matrix produces a matrix as a product of its lower triangular matrix and upper triangular matrix. In the lower triangular matrix (L), all values above the main diagonal are zero, and in the upper triangular matrix (U), all values below the main diagonal are zero. In this article, we'll write a C++ program to perform LU decomposition of any matrix. Example Steps to perform LU Decomposition of Matrix LU Decomposition breaks a matrix A into two matrices L (lower triangular) and U (upper triangular) such that: A = L * U We ... Read More

C++ Program to Implement Fisher-Yates Algorithm for Array Shuffling

Nishu Kumari
Updated on 30-May-2025 18:02:00

820 Views

Shuffling an array means rearranging its elements in a random order. The Fisher-Yates algorithm creates a shuffle where every possible order is equally likely to happen. In this article, we'll show you how to write a C++ program that uses Fisher-Yates algorithm to shuffle an array. Fisher-Yates Algorithm to Shuffle an Array To shuffle an array, we use the Fisher-Yates algorithm. It works by swapping each element with another randomly selected element from the part of the array that we haven't shuffled yet. Here are the steps we follow: First, we start ... Read More

Convert an int to ASCII character in C/C++

Nishu Kumari
Updated on 30-May-2025 18:01:36

37K+ Views

In C and C++, every character like 'A', 'b', '3', or '@' is stored as a number called its ASCII value. For example, 'A' is 65, and 'a' is 97. Given an integer like 97, we can convert it to its corresponding ASCII character which is 'a'. In this article, we will learn how to write a C and C++ program to convert an integer into its ASCII character. For example, we're given any integer from 0 to 127 (because the ASCII table contains 128 characters), and we need to convert it into its corresponding ASCII character: Input: 65 ... Read More

Determining how many digits there are in an integer in C++

Nishu Kumari
Updated on 30-May-2025 18:01:08

32K+ Views

Here we will see how to check how many digits are there in an integer in C++. At first we will see the traditional rule, then a shorter method and finally another approach to find the digit count. For example, given a single integer (which can be positive, negative, or zero): //Example 1 Input: 12345 Output: 5 //Example 2 Input: -789 Output: 3 Note: The minus sign (if present) is not counted as a digit. Determining how many digits there are in an integerWe can count the number of digits in an integer using different methods ... Read More

Java Program to Add Characters to a String

Shriansh Kumar
Updated on 30-May-2025 17:54:49

13K+ Views

Java Program to Add Characters to a String Java provides different ways to add characters to a string. We can add characters in the beginning or at the end or at any position according to the need. In this article, we are going to see three different approaches to do so: Using '+' operator Using methods of StringBuffer and StringBuilder classes ... Read More

Merge contents of two files into a third file using C

Revathi Satya Kondra
Updated on 30-May-2025 17:52:18

1K+ Views

In C language, file handling is used for various file actions such as to write, read, merge, etc. Merging Contents of Two Files into a Third FileTo merge the contents of two files into a third file, you need to open the first two files (whose content will be merged into the third file) in read mode and the third file in write mode. After opening the files, read the contents of the first file and write them to the third file, and similarly with the second file and appending them to the third file. Example Scenario Imagine these are ... Read More

Advertisements