Aishwarya Naglot

Aishwarya Naglot

Writing clean code… when the bugs aren’t looking.

About

Developer by passion, debugger by instinct. Forever building, occasionally breaking, constantly evolving.

105 Articles Published

Articles by Aishwarya Naglot

Page 2 of 11

How do we check if a String contains a substring (ignoring case) in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 5K+ Views

Problem Statement The task is, given a string and a substring, you have to check if a substring is present in a string or not. Do not mind if the case of the string and substring is different, it should not matter. For example, if the string is "Hello World" and the substring is "hello", then the output should be true. Even if the substring is "HELLO" or "HeLLo", the output should be true. Solution To solve this problem, we will first convert the string and the substring to lowercase using the toLowerCase() method. The toLowerCase () method of the ...

Read More

Sorting contents of a string that holds integer values in Java

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 4K+ Views

Problem Statement Here we have a string that contains integer values, our task is to sort those integer values in ascending order. For example, if the string is "31134", the sorted string should be "11334". Solution We can solve the above problem using multiple ways: Using char array Using Stream API Using Bubble Sort Using char array We will use the toCharArray() method of the String class to convert the string into a character array. Then we will sort the character array using the Arrays.sort() method. ...

Read More

How to get first and last elements from ArrayList in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 16K+ Views

ArrayList is a part of the Java Collections Framework. Which is a dynamic type of array that can grow and shrink as needed. It is a resizable array implementation of the List interface. The ArrayList class is used when we want to store a list of elements in a dynamic array. In this article, let's learn how to get the first and last elements from an ArrayList in Java. The get() method of the ArrayList class accepts an integer representing the index value and returns the element of the current ArrayList object at the specified index. Therefore, if you pass ...

Read More

How can a String be validated (for alphabets) in java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 5K+ Views

Problem Statement The given problem is to validate a string to check if that string contains only alphabets (both uppercase and lowercase) and does not contains any other characters like numbers, special characters, etc.. For example, the string "HelloWorld" is valid as it contains only alphabets, while "Hello123" is not valid as it contains numbers. Solution We can solve this problem by using following methods: Using Regular Expressions Manual Checking using loop Using Character.isAlphabetic() Using Regular Expressions We can use regular expressions to validate a string for alphabets. The regular expression ^[a-zA-Z]+$ matches a string that contains only ...

Read More

How to create a variable that can be set only once but isn\'t final in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 2K+ Views

How to create a variable that can be set only once, meaning it can be assigned a value only once but is not final in Java? Solution In Java we can solve the above using the following two methods: Using a custom wrapper class Using an AtomicReference Using a custom wrapper class We can create a custom wrapper class that allows setting a value only once. The class will have a boolean flag to check if the value has already been set. Wrapper classes are used for converting primitive data types into objects. We will use this for setting ...

Read More

How to Convert a String to Hexadecimal and vice versa format in java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 18K+ Views

In this article, we will learn how to convert a string to hexadecimal and hexadecimal to string in Java. Hexadecimal is a base-16 number system that uses 16 symbols to represent a number. Those symbols can be 0-9 and A-F letters. String to Hexadecimal in Java To convert a string to hexadecimal in Java, we can use the toHexString() method of the Integer class accepts an integer as a parameter and returns a hexadecimal string. Following are the steps to convert a string to hexadecimal: Get the desired String. Create an empty StringBuffer object. Convert it into a ...

Read More

How to extract an HTML tag from a String using regex in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 3K+ Views

In this article, we will see how to extract an HTML tag from a string using regex in Java. We can achieve this in multiple ways, but if we use regex, it will be better than others and also give us fast performance. What is Regex? Regex is a sequence of characters that describes a search pattern that is used to find a particular pattern in a String. It is also known as a regular expression or regexp. We use regex for pattern matching or searching or replacing a String. We will use the java.util.regex package of Java that provides ...

Read More

What are the rules of exception handling with respect to method overriding in java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 845 Views

While a superclass method throws an exception when overriding it, you need to follow certain rules. We will be discussing these rules in this chapter. What is Exception Handling in Java? Exception handling is a mechanism to handle errors in the program. For example, if a program tries to divide a number by zero, it will throw an ArithmeticException. In such cases, the program will terminate abnormally. To avoid this, we can use exception handling. Now, let's discuss the rules of exception handling with respect to method overriding. Those are: Should throw the same exception or a subtype ...

Read More

How do we create a string from the contents of a file in java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 28-Aug-2025 357 Views

We can use the method below to read the contents of a file in Java: Using the java.util.Scanner class. Using the java.io.BufferedReader class. Using the java.nio.file.Files class. Using the Scanner class In Java, you can read the contents of a file in several ways. One way is to read it into a string using the java.util.Scanner class, to do so, follow the steps below: Instantiate the Scanner class, with the path of the file to be read, as a parameter to its constructor. Create an empty String buffer. Start a while loop with a condition, if the ...

Read More

How do we extract all the words start with a vowel and length equal to n in java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 28-Aug-2025 2K+ Views

In this article, we will learn to extract all the words that start with a vowel and have a length equal to n from a given text file or string in Java. We can solve this problem using the following ways: Using the split() method of the String class. Using the StringTokenizer class. Using Regular Expressions. Using the split() method of the String class To extract all the words that start with a vowel and have a length equal to n from a given text file or string in Java, we can use the following steps: The ...

Read More
Showing 11–20 of 105 articles
« Prev 1 2 3 4 5 11 Next »
Advertisements