Glossary
ArrayLists
A resizable array implementation of the List interface that allows for efficient random access to elements.
Example:
When you need to quickly look up or change any item in a list, like accessing the 5th student in a class roster, an ArrayList is ideal.
Autoboxing
The automatic conversion that the Java compiler makes between primitive types and their corresponding wrapper classes.
Example:
When you add an int value directly to an ArrayList<Integer>, Java performs autoboxing to convert the int into an Integer object.
Deques
A double-ended queue, similar to a list, but elements can only be added or removed from either the beginning or the end.
Example:
Imagine a line at a popular food truck where people can join at the back or leave from the front; this behavior is like a Deque.
Generics
A feature in Java that allows classes, interfaces, and methods to operate on objects of various types while providing compile-time type safety.
Example:
Using ArrayList<String> ensures that your list will only hold String objects, catching type errors during compilation thanks to Generics.
Java Collections Framework
A set of interfaces and classes in Java that provide a unified architecture for representing and manipulating collections of objects.
Example:
The Java Collections Framework includes tools like ArrayList and HashSet to manage groups of data efficiently.
LinkedLists
A type of List where elements are linked sequentially, making sequential access efficient but direct access to middle elements slow.
Example:
If you're building a music player that mostly plays songs in order, a LinkedList might be suitable for the playlist.
Lists
An ordered collection data type that allows duplicate elements and maintains the insertion order of its elements.
Example:
To keep track of a playlist where songs can repeat and their order matters, you would use a List.
Maps
A collection data type that stores pairs of items, where each pair consists of a unique key and an associated value.
Example:
Storing student names (keys) and their corresponding grades (values) is a classic use case for a Map.
Sets
A collection data type where each item is unique (no duplicates) and the order of elements is not guaranteed.
Example:
If you want to store a list of unique student IDs, a Set would be perfect because it automatically prevents duplicates.
Unboxing
The automatic conversion that the Java compiler makes from a wrapper class object to its corresponding primitive type.
Example:
If you retrieve an Integer object from an ArrayList and assign it to an int variable, Java performs unboxing to get the primitive value.
Wrapper Classes
Classes in Java that encapsulate primitive data types (like `int` or `double`) into objects, allowing them to be used in contexts where only objects are permitted.
Example:
Integer is a Wrapper Class for the primitive int, enabling you to store integer values in an ArrayList<Integer>.