Check If Two Strings Are Anagram in Java

Shriansh Kumar
Updated on 18-Jun-2025 19:11:41

5K+ Views

An anagram is a word or phrase formed by rearranging the letters of two or more words. Suppose there are two strings. If both strings contain the same set of letters along with the same number of letters, regardless of their order, then we can say that both strings are anagrams; otherwise, not. Now, let's understand how we can find if two strings are anagrams or not in Java. How to Check if two Strings are Anagram? Follow the steps given below to solve the Anagram String problem: ... Read More

Java Nested Loops with Examples

Shriansh Kumar
Updated on 18-Jun-2025 19:09:16

2K+ Views

Loops in Java are called control statements because they decide the flow of execution of a program based on some condition. Java allows the nesting of loops. When we put a loop within another loop, then we call it a nested loop. Nested loops are used when we need to iterate through a matrix array and when we need to do any pattern-based questions. In this article, we are going to learn about Java nested loops with examples. Nested Loops in Java We can create nested loops for the following control statements in Java: ... Read More

Java Program to Reverse a Number

Shriansh Kumar
Updated on 18-Jun-2025 19:05:39

1K+ Views

For a given input number, write a Java program to reverse its digits. In reverse operation, we print the digits of given number from the last to start. The digit at the last position is swapped with the digit at the first position, the second last digit is swapped with second position digit and so on. Example Scenario: Input: number = 123456; Output: rev_number: 654321 How to Reverse a Number in Java? There are multiple ways to reverse the digits of a given number. We are going to discuss the following: Using ... Read More

What Happens If We Directly Call the run() Method in Java

Vivek Verma
Updated on 18-Jun-2025 19:00:48

280 Views

The run() method of the Thread class is called internally after the start() method is invoked to begin a new thread. However, if the run() method is called directly (without start()), it does not start a separate thread and executes within the current thread. The run() Method In Java, the run() method of the Thread class is used to define the sequence of actions that a thread will execute. This method will be invoked by the Java Virtual Machine (JVM) implicitly; we can also invoke this method explicitly in the current thread without calling the start() method. Note! The run() ... Read More

POSIX Character Classes in Java Regex

Maruthi Krishna
Updated on 18-Jun-2025 18:55:44

832 Views

In this article, we will learn about the p{ASCII} of the POSIX character class in Java regex. What is \p{ASCII}? In Java regex, \p{ASCII} POSIX character class matches any of the characters that fall within ASCII. ASCII (American Standard Code for Information Interchange) defines a character encoding standard consisting of 128 characters (0-127). This class matches the ASCII characters within the range of \x00-\x7F. Printable characters in the \p{ASCII} of the Java Regex are: Numbers (0 to 9) Uppercase letters (A to Z) Lowercase letters (a ... Read More

Print Elements of a HashMap in Java

Vivek Verma
Updated on 18-Jun-2025 18:53:34

3K+ Views

In Java, a HashMap is a subclass of the AbstractMap class and is used to store key-value pairs. Each key in the map is mapped to a single value in the map, and the keys are unique.Printing Java HashMap Elements  We can insert a key only once in a map, and duplicate keys are not allowed, but the value can be mapped to multiple keys. We can add the elements using the put() method of the HashMap class and iterate over the elements using the Iterator interface. Java HashMap provides various ways to print its elements as follows: ... Read More

Check If a Double or Float is NaN in C++

Aman Kumar
Updated on 18-Jun-2025 18:47:53

14K+ Views

In this article we will check whether a double or floating point number is NaN (Not a Number) in C++. Checking if a Double or Floating Point Number is NaN To check, we can utilise the isnan() method. The isnan() function is available in the cmath library. This function was introduced in C++ version 11. So From C++11 next, we can use this function. The isnan() function is used to determine whether a double or floating point number is not-a-number (NaN) value. Return true if num is NaN, false otherwise. C++ Program to Check Double or Float Number is NaN ... Read More

Assertions in C and C++

Aman Kumar
Updated on 18-Jun-2025 18:46:54

476 Views

What is an Assertions in C/C++? An assertion is a statement used to test assumptions made by the program. When an assertion fails, the program displays an error and stops. This is mainly used for debugging. In C and C++, assertions are handled using the assert() macro defined in the (C) or (C++) header file. Following is the declaration for assert() Macro. #include // in C // or #include in C++ assert(expression); The parameter of this assert() is expression: This can be a variable or any C/C++ expression. If ... Read More

Difference Between Namespace and Class in C++

Aman Kumar
Updated on 18-Jun-2025 18:44:13

6K+ Views

In this article, we will see the differences between namespace and class in C++. Namespace and classes are two different concepts, so let's discuss them: Classes are datatypes. It is an expanded version of the structures. Classes can contain data members and functions as members, but namespaces can contain variables and functions by grouping them into one and cannot be created as objects; it is used as additional information to differentiate similar functions, classes, variables, etc. Variables, functions with the same name can be placed in different namespaces. What is Namespace? The namespace is a feature that provides a way ... Read More

Variadic Function Templates in C++

Aman Kumar
Updated on 18-Jun-2025 18:43:09

370 Views

What is Variadic Function In mathematics and in computer programming, a variadic function is a function of indefinite arity, i.e., a function that accepts a variable number of arguments. So, In C++ programming, we can say that a function that accepts a variable number of arguments is variadic function. Why Variadic Function Templates Are Used? In C++, templates can only have a fixed number of parameters, which must be specified at the time of declaration. However, variadic templates can help to solve this issue. Syntax to Create Variadic Function Following is the variadic function template syntax: template return_type function_name(arg var1, ... Read More

Advertisements