Having fun writing and exploring collection classes and their usages.
-
The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with five operations that allow a vector to be treated as a stack. The usual push and pop operations are provided, as well as a method to peek at the top item on the stack, a method to test for whether the stack is empty, and a method to search the stack for an item and discover how far it is from the top. When a stack is first created, it contains no items.
A more complete and consistent set of LIFO stack operations is provided by the Deque interface and its implementations, which should be used in preference to this class. For example: Deque stack = new ArrayDeque();
-
-
[DeQueue DS implementation] (https://www.programiz.com/dsa/deque) and https://www.youtube.com/watch?v=kLBuJ1Hle8g&ab_channel=GridoWit
-
-
-
-
The Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created.
Each vector tries to optimize storage management by maintaining a capacity and a capacityIncrement. The capacity is always at least as large as the vector size; it is usually larger because as components are added to the vector, the vector's storage increases in chunks the size of capacityIncrement. An application can increase the capacity of a vector before inserting a large number of components; this reduces the amount of incremental reallocation.
As of the Java 2 platform v1.2, this class was retrofitted to implement the List interface, making it a member of the Java Collections Framework. Unlike the new collection implementations, Vector is synchronized. If a thread-safe implementation is not needed, it is recommended to use ArrayList in place of Vector
-
-
List.of() --> returns immutable List in terms of size , remove and add not allowed also set(replace) not allowed
-
Arrays.asList() --> returns immutable List in terms of size, remove and add not allowed but set(replace) allowed Object state of each element of list can be updated in both the cases of list examples.
1. While passing list as param to a method that doesn't modify it. 2. Use it when multiple threads are sharing the list and you want the same list to be used by all threads.
-