Maruthi Krishna has Published 464 Articles

How to check multiple regex patterns against an input? Using Java.

Maruthi Krishna

Maruthi Krishna

Updated on 15-Jul-2025 17:58:40

6K+ Views

In Java, the strings that are used to find the pattern are known as regular expressions. In this article, we will learn to check multiple regex patterns against an input, and it can be done by using 2 approaches. Using Metacharacter ... Read More

How to overwrite a line in a .txt file using Java?

Maruthi Krishna

Maruthi Krishna

Updated on 12-May-2025 19:07:46

20K+ Views

The given task is to overwrite a line in a .txt file with new content. Assume we have a .txt file with the following content - Line 1: Hello World Line 2: This is a test file. Line 3: This line will be overwritten. Line 4: Goodbye! We want ... Read More

What happens when we try to add a duplicate key into a HashMap object in java?

Maruthi Krishna

Maruthi Krishna

Updated on 08-May-2025 11:52:38

4K+ Views

No, HashMap does not allow duplicate keys. The HashMap is a class that implements the Map interface. It is based on the Hash table. It is used to store key-value pairs. It allows null keys and values, but it does not allow duplicate keys. You can store key-value pairs in ... Read More

Reading data from keyboard using console class in Java

Maruthi Krishna

Maruthi Krishna

Updated on 08-May-2025 10:00:29

1K+ Views

The Console class is part of the Java.io package and is used to read input from the keyboard or user and write output to the console. Unlike Scanner, the Console class provides methods to read text and passwords. If you read a password using the Console class, it will not be displayed to the ... Read More

Why do we get ClassNotFoundException when the class exists in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 24-Apr-2025 15:30:50

4K+ Views

Whenever we try to load a class, ClassNotFoundException occurs when the application tries to load a class at runtime using methods like Class.forName() or ClassLoader.loadClass(), but the JVM cannot locate the class in the classpath. The following are the reasons of ClassNotFoundException occurence and they are - ... Read More

Can we change method signature in overriding in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 24-Apr-2025 12:34:06

2K+ Views

No, you cannot change the method signature while overriding. Changing the method signature becomes method overloading, not overriding. Now, let's understand why - Method Signature In Java, a method signature consists of - Method name: It ... Read More

Difference between constants and final variables in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 24-Apr-2025 11:00:25

13K+ Views

In Java, both constants and final variables are used to define variables that cannot be changed after initialization. But they have some differences. In this article, we will learn how they are different. Final Variable A final variable in Java means you cannot reassign it after it has been initialized. ... Read More

How to Sort a String in Java alphabetically in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 22-Apr-2025 11:29:01

91K+ Views

Sorting a string alphabetically means rearranging its characters in order, from A to Z. For example, the string "java" becomes "aajv" after sorting. Different ways to sort a String Alphabetically There are two ways to do this in Java using different approaches - ... Read More

In how many ways you can retrieve the elements of a collection in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 22-Apr-2025 11:25:46

3K+ Views

In Java, the collections framework provides various classes like ArrayList, HashSet, and LinkedList to store groups of elements. But once data is stored, how do you access or retrieve it? Java provides multiple ways to retrieve elements from collections, depending on whether you're reading values, modifying them during traversal, or iterating forward ... Read More

How many ways are there to convert an Array to ArrayList in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 22-Apr-2025 11:23:59

445 Views

When working with collections in Java, you might need to convert an array to an ArrayList. This is useful because ArrayList offers more flexibility, such as dynamic sizing and built-in methods for adding, removing, and searching elements. Need for Converting an Array to an ArrayList Arrays in Java have a ... Read More

Advertisements