Map in Java: HashMap, LinkedHashMap and TreeMap
A Map stores key to value pairs with unique keys, and it is the collection you will reach for most often.
Suitable for beginners.
58 notes tagged
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.
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.
Packages give classes a unique name and a visibility boundary, and imports simply save you from writing that full name every time.
Inheritance lets a subclass acquire the members of a superclass, creating an is-a relationship that polymorphism is built on.
Encapsulation hides internal state behind a deliberate public surface, so a class can guarantee its own rules stay true.
static binds a member to the class rather than to any instance, which changes when it is created, how it is accessed and what it can see.
Inside an instance method, this is a reference to the object the method was called on, which resolves shadowing and enables chaining.