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

Iterate through elements of Java LinkedHashSet

Aishwarya Naglot
Aishwarya Naglot
Updated on 28-Jul-2025 525 Views

LinkedHashSet is a part of Java's Collection Framework. It is a type of Set that keeps the order of elements the same as they were added. It uses a combination of a hash table and a linked list to store elements.Our task is to traverse/iterate through the elements of a LinkedHashSet in Java. Let's look at some scenarios to understand the problem better: Scenario 1 Input: {1, 2, 3, 4, 5} Output: 1 2 3 4 5 Explanation: The LinkedHashSet contains the elements 1, 2, 3, 4, and 5. When we iterate through it, we get the elements in the ...

Read More

Check if a Java HashSet Collection contains another Collection

Aishwarya Naglot
Aishwarya Naglot
Updated on 28-Jul-2025 1K+ Views

HashSet is a class in Java that implements the Set interface. It is used for storing unique elements. Our task is to check if a HashSet contains another collection in Java. Let's look at some scenarios to understand the problem better: Scenario 1 Input: {1, 2, 3, 4, 5} Collection to check: {2, 3} Output: true Explanation: The HashSet contains all the elements of the collection {2, 3}. Scenario 2 Input: {1, 2, 3, 4, 5} Collection to check: {6, 7} Output: false Explanation: The HashSet does not contain all the elements of the collection {6, 7}. Checking ...

Read More

Check if a particular key exists in Java LinkedHashMap

Aishwarya Naglot
Aishwarya Naglot
Updated on 25-Jul-2025 717 Views

LinkedHashMap is a data structure in Java that is part of the Java Collections Framework. It is very similar to HashMap.It stores key-value pairs, where each key is unique, and it allows null values, but allows only one null key. The main difference is that the LinkedHashMap returns the elements in the order they were inserted. This is because it maintains a linked list with entries in the map, which helps it to retain the insertion order of the elements. Our task is to check if a particular key exists in a LinkedHashMap in Java. Scenario 1 Following is a ...

Read More

Add all the elements from a collection to the HashSet in Java

Aishwarya Naglot
Aishwarya Naglot
Updated on 21-Jul-2025 648 Views

HashSet in Java implements the Set interface, which belongs to the Java Collections Framework and is a part of the java.util package. It stores unique elements, which means we cannot store any duplicate (appearing more than once) values in a HashSet. The given task is to add all the elements of another collection to a HashSet object in Java. For example, if we have a collection ArrayList with elements [1, 3, 4, 5, 5]. Our task is to add all these elements to a HashSet, maybe to remove duplicates from the list, or for any other reason. Adding Elements from ...

Read More

Add months to current date using Calendar.add() method in Java

Aishwarya Naglot
Aishwarya Naglot
Updated on 21-Jul-2025 5K+ Views

The given task is to add months to a date (object) using the add() method of the Calendar class. For example, if we need to add 5 months to the date: 26-06-2025, the new date would be 26-11-2025. Calendar.add() method in Java The calender.add() method in Java is used to add a specified amount of time to any field of the Calendar. Using this method, we can add months, years, days, etc. This method accepts two parameters: the first one is the field we want to add to, and the second one is the amount we want to ...

Read More

Add elements to HashMap in Java

Aishwarya Naglot
Aishwarya Naglot
Updated on 21-Jul-2025 7K+ Views

HashMap is a part of the Java Collections Framework, it is available in java.util package. It implements the Map interface, and it is used for storing two values at a time: a key and a value. The HashMap key is used to access the associated value. A Java HashMap is similar to a dictionary, where we have a word (key) and its meaning is considered as a value. In this article, we will learn how to add elements to a HashMap in Java Programming. The following are the ways to add elements to a HashMap in Java: Using ...

Read More

Java Program to Check if a set is the subset of another set

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

In this article, we will understand how to check if a Set is a subset of another set. A Set is a Collection that cannot contain duplicate elements. It models the mathematical set abstraction. The Set interface contains only methods inherited from Collection and adds the restriction that duplicate elements are not allowed. Following are the ways to check if a set is a subset of another set: Using containsAll() Method Using Stream API Using containsAll() Method In Java, the set interface has a method called containsAll() that checks ...

Read More

Java Program to Pass ArrayList as the function argument

Aishwarya Naglot
Aishwarya Naglot
Updated on 18-Jun-2025 4K+ Views

The ArrayList is a resizable array, which is part of java.util package. The difference between a built-in array and an ArrayList in Java is that the size of an array cannot be modified. In this article, we will understand how to pass an ArrayList as a function argument. Following are the ways to pass an ArrayList as a function argument: Using Function Argument Using Return Type Using Function Argument We can pass an ArrayList as a function argument in Java. The function can take an ArrayList as a parameter and perform operations ...

Read More

Java Program to Convert the local Time to GMT

Aishwarya Naglot
Aishwarya Naglot
Updated on 18-Jun-2025 3K+ Views

In this article, we will learn how to convert the local time to GMT (Greenwich Mean Time) in Java. We need this conversion when we want to standardize time across different time zones or when working with systems that require GMT. We will cover the following methods to convert local time to GMT: Using ZonedDateTime class Using Calendar Class Using Date Class Using ZonedDateTime Class ZonedDateTime class was introduced in Java 8, which is used for converting local time to GMT. We can use the ...

Read More

Java program to detect loop in a LinkedList

Aishwarya Naglot
Aishwarya Naglot
Updated on 18-Jun-2025 632 Views

What is a LinkedList? A Linked list is a sequence of data structures where each node contains two parts as follows - Data: The value or information stored in the node. Next: A reference (or pointer) to the next node in the sequence. Detecting a Loop in a LinkedList A loop or cycle means that the last node of a linked list is connected back to one of the nodes earlier in the list, creating a cycle. Or, the next pointer of a node points to itself. The following are the ways ...

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