Java Notes Final
Java Notes Final
- Final is used to make variables/constants unchangeable. It may be a final variable or final class.
- Finally block always runs after try-catch block. In finally block, the specific code should always run
Finalize()
- This finalize method is a special method in Java that is called by garbage collection before an
- ArrayList & LinkedList are both classes in Java used to store a list of elements, but they work
differently.
- ArrayList uses a dynamic array to store elements. It's faster when you want to access elements
- LinkedList elements are connected by links. It is faster when you want to add or remove elements
- Both HashMap & Hashtable are used to store data in key-value pairs, but they have key
differences.
- HashMap is not synchronized, which means it is not thread-safe, but it performs better in
Java Notes
single-threaded applications.
- Hashtable does not allow any null key or value, while HashMap allows null values.
- To iterate, I use a for-each loop with entrySet() to get both key & value.
- LinkedList is used when frequent insertions & deletions are required, especially in the middle of the
list.
- TreeSet stores elements in sorted (ascending) order because it uses tree structure.
- LinkedHashMap stores in insertion order, so keys are returned in the order they were added.
- TreeMap stores keys in sorted (ascending) order using Red-Black tree structure.
7) Iterator vs ListIterator
- Iterator works with all types of collections like Set, List, Map, but it can only move forward.
- ListIterator works only with List types & can move both forward & backward.