java core

Your blog category

Hashtable

Hashtable in Java is a legacy class that implements the Map interface and extends Dictionary. It is synchronized and stores key-value pairs in a hash table, where keys and values are not ordered. Hashtable does not allow null keys or values and provides thread-safe operations for basic map operations. Here’s an overview of the syntax,

Hashtable Read More »

TreeMap

TreeMap in Java is an implementation of the NavigableMap interface and extends AbstractMap. It stores key-value pairs in a sorted order based on the natural ordering of keys or a custom Comparator provided at the time of creation. TreeMap is implemented as a red-black tree, which provides guaranteed log(n) time complexity for most operations like

TreeMap Read More »

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 »

Scroll to Top