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 6 of 11

How do you create a list with values in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 05-Jun-2025 1K+ Views

A List is a Collection in Java that is used for storing elements in sequence. In this article, we will be learning how to create a list with values in Java. Ways to Create a List with Values in Java There are various ways to create a list with values in Java. Below are the different approaches: Using Arrays.asList() method Using Stream.of() method Using List.of() method Using Arrays.asList() method The Arrays.asList() method returns the elements of the current array in the form of a List.  This method ...

Read More

How do you get the index of an element in a list in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 05-Jun-2025 22K+ Views

List is a collection in Java that allows us to store elements. In this article, we will learn how to get the index of an element in a List in Java. We have various ways to get the index of an element in a List in Java. They are - Using the indexOf() method Using a for loop Using Stream API Using the indexOf() method The indexOf() method returns the index of the first occurrence of the specified element in this list, or -1 if this ...

Read More

Java program to reverse a string using recursion

Aishwarya Naglot
Aishwarya Naglot
Updated on 05-Jun-2025 2K+ Views

In this article, we will learn to reverse a string using recursion in Java. Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is known as a recursive call of the function. You can reverse a string using the recursive function as shown in the following program. Steps to reverse a string using recursion  Following are the steps to reverse a string using recursion - Create a class called StringReverse with a method reverseString that takes ...

Read More

Java program to replace a character at a specific index

Aishwarya Naglot
Aishwarya Naglot
Updated on 30-May-2025 5K+ Views

In this article, we'll learn how to replace a character at a specific index in a string. Strings in Java are sequences of characters enclosed in double-quotes (" "). We use strings to represent text in our programs. Problem Statement You are given a string, an index, and a character. Your task is to replace the character at the specified index in the string with the new character. Input string: Java Programming, Index: 6 Output: Java P%ogramming Different Approaches There are multiple ways to achieve this in Java. Below are two common approaches: Using substring() ...

Read More

How do you make a shallow copy of a list in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 30-May-2025 1K+ Views

In this article, we will learn how to make a shallow copy of a List in Java. What is the List in Java? List is a part of the Java collection framework. It stores elements sequentially and also allows us to store duplicate elements. It is an interface, not a class, so it cannot be instantiated directly. However, there are several classes that implement the List interface, such as ArrayList, LinkedList, and Vector. Shallow Copy of a List A shallow copy means it is a copy of the original list, but elements in the copied list are still referencing the ...

Read More

How do you turn an ArrayList into a Set in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 30-May-2025 12K+ Views

In this article, let's learn how to convert an ArrayList into a Set in Java. ArrayList is a collection that allows us to store duplicates, whereas Set is a collection that does not allow duplicates. So, when we convert an ArrayList to a Set, all the duplicate elements will be removed. If someone tries to add duplicate elements to a Set, it will not throw an error but will simply ignore the duplicate elements. Let's take an example: Input: [1, 2, 3, 4, 5, 5, 6] Output: [1, 2, 3, 4, 5, 6] Ways to Convert an ArrayList to ...

Read More

How to access the JSON fields, arrays and nested objects of JsonNode in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 13-May-2025 34K+ Views

What are JSON and JsonNode? JSON is a format that is used to store data and exchange data between a server and a client. To know more about JSON, you can refer to the JSON Tutorial. A JsonNode is Jackson's tree model for JSON. To read JSON into a JsonNode with Jackson by creating an ObjectMapper instance and call the readValue() method. We can access a field, array or nested object using the get() method of the JsonNode class. We can return a valid string representation using the asText() method and ...

Read More

How to serialize a null field using Gson library in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 13-May-2025 8K+ Views

Gson is a library in the Java that is mainly used for converting Java objects to JSON and vice versa. By default, the Gson object does not serialize the fields with null values to JSON. If a field in a Java object is null, Gson excludes it.Serializing a Null Field Using Gson We can force Gson to serialize null values via the GsonBuilder class. We need to call the serializeNulls() method on the GsonBuilder instance before creating the Gson object. Once serializeNulls() has been called, the Gson instance created by the GsonBuilder can include null fields in the serialized JSON. ...

Read More

How to deserialize a JSON into an existing object in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 13-May-2025 3K+ Views

Deserialization is the process of converting a JSON string into a Java object. In this example, we will learn how to deserialize a JSON string into an existing object in Java. There are libraries available in Java that can help us to deserialize a JSON string into an existing object. Some of the popular libraries are: Using Gson Using Jackson Using Flexjson Let's learn how to use each of these libraries to deserialize a JSON string into an existing object in Java. Deserializing JSON Object Using ...

Read More

Differences between fromJson() and toJson() methods of Gson in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 13-May-2025 5K+ Views

Gson is a Java library which is developed by Google and used to convert Java objects into JSON and vice versa. It is mostly used in applications where data can be exchanged in JSON format. There are two useful methods in Gson that we are going to discuss in this article. These methods are fromJson() and toJson(). The fromJson() Method The fromJson() method is used to convert a JSON string into a Java object. It takes two parameters: the JSON string and the class type of the object you want to create. Here is the syntax of the fromJson() method: ...

Read More
Showing 51–60 of 105 articles
« Prev 1 4 5 6 7 8 11 Next »
Advertisements