Author name: javaplanet.io

LinkedHashMap

LinkedHashMap in Java extends HashMap to store key-value pairs in insertion order, which means the order of elements is maintained based on the sequence in which they were inserted. It combines the features of HashMap with a linked list implementation of the entries, allowing predictable iteration order. Methods: Adding Elements: boolean add(element): Adds the specified …

LinkedHashMap Read More »

HashMap

HashMap in Java is a data structure that stores key-value pairs and allows for fast retrieval of values based on their keys. It belongs to the java.util package and implements the Map interface, providing methods to manipulate and access elements efficiently. Here’s an overview of the syntax, methods, and an example demonstrating the use of …

HashMap Read More »

ArrayDeque

ArrayDeque in Java is a double-ended queue implementation that provides more efficient insertion and removal operations compared to LinkedList. It does not have capacity restrictions like arrays and allows elements to be added or removed from both ends of the deque. This makes it suitable for implementing stacks, queues, and dequeues efficiently. Methods: Adding Elements: …

ArrayDeque Read More »

TreeSet

A TreeSet in Java is an implementation of the SortedSet interface, which uses a Red-Black tree structure to store elements in sorted order. The sorting is based on either the natural ordering of elements or a custom comparator provided at the time of TreeSet creation. This makes TreeSet suitable for scenarios where you need elements …

TreeSet Read More »

LinkedHashSet

A LinkedHashSet in Java is an implementation of the Set interface that maintains insertion order of elements, which means when you iterate through a LinkedHashSet, the elements are returned in the order they were inserted. It combines the uniqueness property of HashSet with predictable iteration order provided by a linked list. Constructors Constructor Description LinkedHashSet() …

LinkedHashSet Read More »

HashSet

A HashSet in Java is an implementation of the Set interface, which represents a collection of unique elements. It does not allow duplicate elements and does not guarantee the order of elements. The HashSet class uses a hash table for storage, which provides constant-time performance for basic operations like add, remove, contains, and size, assuming …

HashSet Read More »

Stack

In Java, the Stack interface represents a Last-In-First-Out (LIFO) data structure. It extends the Vector class with respective methods that allow a vector to be treated as a stack.  Push:            void push(E item): Adds an item onto the top of the stack.  Pop:           E pop(): …

Stack Read More »

Vector

A Vector in Java is a legacy class that belongs to the java.util package and is similar to an ArrayList. It represents a dynamic array that can grow or shrink in size as elements are added or removed. Vector is synchronized, meaning it is thread-safe, which ensures that multiple threads can safely access and modify …

Vector Read More »

LinkedList

A LinkedList in Java is another type of data structure that, like an ArrayList, allows you to store and manage a collection of elements. However, unlike an ArrayList, a LinkedList is implemented as a doubly linked list, where each element (or node) in the list contains a reference to the next and previous elements. This …

LinkedList Read More »

ArrayList

An ArrayList in Java is a dynamic data structure that allows you to store and manipulate a collection of elements. It’s part of the java.util package and provides flexibility in handling groups of objects. Methods: Adding Elements add(element): Appends an element to the end of the list. add(index, element): Inserts an element at a specified …

ArrayList Read More »

Scroll to Top