The mutable keyword in C++ is a storage class specifier. It enables non-static, non-const, and non-reference data members (i.e., mutable data member) of a class to be changed even when the object containing them is declared constant. Mutable data members are those members whose values can be changed in runtime even if the object is of constant type. It is just the opposite of a constant. What is Need of Mutable? Sometimes, it is necessary to modify one or more data members of a class/struct through the constant function, even if you do not want the function to update another ... Read More
In C++, calling a virtual function inside a constructor or destructor is dangerous and should generally be avoided. Following are the reasons to avoid calling: When a constructor (or destructor) is running, the object is not fully built (or fully destroyed). At that time, the virtual function table (vtable) points to the version of the class currently being constructed or destructed, not the most derived version. What Happens When You Call a Virtual Function in a Constructor? If you call the virtual function inside a constructor: ... Read More
In this article, we will learn about the ConcurrentHashMap and HashTable in Java. First, we will know about ConcurrentHashMap, the syntax of ConcurrentHashMap, and an example after that will learn about HashTable, the syntax of HashTable, and an example. At the end, we will see a table showing the difference between ConcurrentHashMap and HashTable. What is ConcurrentHashMap in Java? ConcurrentHashMap is a class that was introduced in JDK 1.5. The ConcurrentHashMap is threadsafe as it allows multiple threads to read and write the data without locking the entire map. ConcurrentHashMap applies locks only at the bucket level, called a fragment, while ... Read More
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 ... Read More
In-order traversal processes each node by visiting the left subtree first, then the node, 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 need ... Read More
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 ... Read More
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 ... Read More
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 ... Read More
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 ... Read More
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 ... Read More