Found 34484 Articles for Programming

Iterate TreeMap in Reverse Order in Java

Shriansh Kumar
Updated on 20-Jul-2023 16:47:58

700 Views

TreeMap is a class of Java Collection Framework that implements NavigableMap Interface. It stores the elements of the map in a tree structure and provides an efficient alternative to store the key-value pairs in sorted order. In other words, it always returns the elements in ascending order. However, Java provides a few ways to iterate through the TreeMap in descending order. In this article, we are going to explore the ways of iterating TreeMap in Reverse order. Iterate TreeMap in Reverse Order in Java We will use the following ways to print elements of TreeMap in reverse order: ... Read More

Remove all the occurrences of a character from a string using STL

Way2Class
Updated on 20-Jul-2023 18:45:13

2K+ Views

STL basically stands for Standard Template Library, which is a collection of pre-written code frequently used in Data structures and Algorithms. It was developed in the early 1990s by Meng Lee and Alexander Stepanov. It consists of mainly three components known as containers, algorithms and iterators. Containers are objects that stores and manipulate data such as list, vector, set, map and stack. Algorithm are functions which works on the data stored in the containers such as searching, sorting and also manipulating data. Iterators are object that navigates through the elements of a container easily. STL has became an ... Read More

Count removal of pairs required to be empty all Balanced Parenthesis subsequences

Way2Class
Updated on 20-Jul-2023 17:39:09

39 Views

C compiler treats a string as an array of characters, so it is easy to remove characters of a string based on their position. The first and last position of the string have to be checked for the presence of parenthesis and have to be removed. The string can be copied into another variable and presented. There are many predefined functions in C that can be used effectively to manipulate strings. Removing a character from the starting or ending position is easily achieved in C with the help of the functions. Removing starting and ending paranthesis from string ... Read More

How to Get and Set Default Character Encoding or Charset in Java?

Shriansh Kumar
Updated on 20-Jul-2023 16:44:22

1K+ Views

In Java, the default character encoding is determined by the 'file.encoding' which is a system property and is usually set by the operating system or the JVM. However, sometimes a Java programmer may need to get or set the default character encoding programmatically for various reasons. For this purpose, the 'java.nio.charset' package provides various classes and methods. In this article, we are going to learn the different ways to get and set default character encoding or charset. Get and Set Default Character Encoding or Charset in Java First, let's discuss what is default character encoding or charset. ... Read More

Count of primes after converting given binary number in base between L to R

Way2Class
Updated on 20-Jul-2023 17:36:33

67 Views

The title "Count of primes after converting given binary number in base between L and R" refers to a math problem that involves converting a binary number into a base between L and R and then counting the number of prime numbers that come from the conversion. In math, a prime number is a whole number that is greater than 1 and can only be divided by 1 and itself. To turn a binary number into a number with a different base, the number has to be written in a different number system. The number system's base is the number ... Read More

How to validate GST (Goods and Services Tax number using Regular Expression?

Way2Class
Updated on 20-Jul-2023 17:21:46

2K+ Views

The government issues a unique identification number known as a GST number to businesses and individuals who have registered for GST. As part of the validation procedure, the GST number is checked for correctness and legitimacy. The format of the number is frequently checked during the verification process to make sure it is correct and conforms to the format needed by the tax authorities of the relevant country. In order to confirm the validity of the number and that it belongs to the person seeking it, the verification phase may also involve cross-referencing it with the database of the tax ... Read More

How to Generate MD5 Checksum for Files in Java?

Shriansh Kumar
Updated on 20-Jul-2023 16:41:13

347 Views

Checksum is an encrypted sequence of characters that are generated with the help of various hashing algorithms like MD5 and SHA-1. The checksum is applicable for the downloadable files. Whenever we generate a checksum for files, it stays the same as long as the file does not get altered or corrupted. In this article, we are going to explore the MD5 checksum which is a hash value used to verify the integrity of files. It is a way of ensuring that the file one has downloaded or transferred is exactly the same as the original one. To generate MD5 checksum ... Read More

How to Fix "class, interface, or enum expected" Error in Java with Examples?

Shriansh Kumar
Updated on 20-Jul-2023 16:37:39

399 Views

Every Java programmer whether a beginner or experienced, encounters numerous errors while writing code. Generally, these errors are categorized as run time and compile time errors. The run-time error occurs while running the code after successful compilation and the compile-time error during compilation. The class, interface, or enum expected is an error thrown during the compilation of source code. It may occur due to several reasons, one of them being misplaced curly braces. In this article, we are going to explore the reasons for this error and corresponding ways to fix the class, interface, or enum expected error. ... Read More

How to fix java.lang.ClassCastException while using the TreeMap in Java?

Shriansh Kumar
Updated on 20-Jul-2023 16:28:18

247 Views

TreeMap is a class of Java Collection Framework that implements NavigableMap Interface. It stores the elements of the map in a tree structure and provides an efficient alternative to store the key-value pairs in sorted order. Note that while creating objects of TreeMap it is necessary to use either the Comparable Interface or Comparator Interface so that we can maintain the sorting order of its elements otherwise, we will encounter a java.lang.ClassCastException. In this article, we are going to explain how to use the Comparable and Comparator Interfaces to fix this ClassCastException in TreeMap. Fixing java.lang.ClassCastException in TreeMap ... Read More

How to Fix java.lang.ClassCastException in TreeSet?

Shriansh Kumar
Updated on 20-Jul-2023 16:25:39

109 Views

The TreeSet is a generic class of Java Collection Framework that implements the SortedSet Interface. It stores the elements of the set in a tree structure. Furthermore, all the elements are stored in a sorted manner and they must be mutually comparable if we are attempting to add custom class objects otherwise we will encounter a java.lang.ClassCastException. Here, custom class objects mean user-defined objects that are created with the help of a constructor. To fix this ClassCastException in TreeSet we can use either the Comparator Interface or the Comparable Interface. Let's discuss them in detail. The general ... Read More

Advertisements