Iterators in Java
An Iterator walks a collection one element at a time, and it is the only safe way to remove during a traversal.
Notes related to the Java language.
100 notes tagged
An Iterator walks a collection one element at a time, and it is the only safe way to remove during a traversal.
A Queue processes elements in an order it decides. A Deque works at both ends, and it is the right way to build a stack in Java.
Buckets, hashing, collisions and resizing. Understanding the mechanism explains the performance and every rule about keys.
A Map stores key to value pairs with unique keys, and it is the collection you will reach for most often.
A Set stores unique elements. The three implementations differ in ordering and in what uniqueness is based on.
A List keeps insertion order and allows duplicates. ArrayList is the default; LinkedList wins only at the ends.
A small set of interfaces describes how groups of objects behave, and many implementations trade memory, ordering and speed differently.
The rules that separate exception handling which helps from exception handling which hides bugs.
A custom exception names a failure in the language of your domain, which makes handling precise and messages meaningful.
throw raises an exception now; throws declares that a method may raise one and leaves the handling to the caller.
try guards a block, catch handles specific failures, finally always runs, and try with resources closes what you opened.
Errors, checked exceptions and unchecked exceptions sit in one hierarchy, and knowing which is which decides how you should react.