
Provides interoperability between unrelated APIs by establishing a common language to pass collections back and forth.Increases performance by providing high-performance implementations of data structures and algorithms.It reduces programming effort by providing built-in set of data structures and algorithms.Algorithms that provides static methods to perform useful functions on collections, such as sorting a list.Concurrent implementation classes that are designed for highly concurrent use.Collection classes such as ArrayList, HashSet etc that are implementations of collection interfaces.These are used to collect different types of objects. Collection interfaces such as sets, lists, and maps.For example, list is used to collect elements and referred by a list object. It is used to store, fetch and manipulate data.
What is collectionĬollection in java can be referred to an object that collects multiple elements into a single unit. It provides many important classes and interfaces to collect and organize group of objects. Java collections framework is contained in java.util package. Prior to Java 2, Java provided adhoc classes such as Dictionary, Vector, Stack and Properties to store and manipulate groups of objects. Java collection framework represents a hierarchy of set of interfaces and classes that are used to manipulate group of objects.Ĭollections framework was added to Java 1.2 version.
#JAVA COLLECTIONS IN DETAIL DRIVER#
Connecting to Access using Type-1 Driver. Method Overriding with Exception Handling. Difference between Classes And Interface. This interface also has special powers: the Java statement for (var x: a) is defined to work only when a is an array or is of a class implementing Iterable.Ī collection is something that (1) can be added to and removed from, (2) can be asked for its size and whether it is empty, (3) has a membership test, (4) can have its items streamed, and (5) can have its items dumped into an array. If something is iterable, you can (1) obtain an iterator for it, (2) obtain a spliterator for it, and (3) iterate over it with its forEach method. Read in order to get the “big picture” sense of what each of the interfaces and classes provide. These notes are provided more as a reference than a tutorial. These will be explained when we get to examples. You’ll see some scary-looking syntax, like, ,, and type names such as Supplier, Consumer, and Predicate. Now it’s time to describe what each interface is all about. HashMap, LinkedHashMap, EnumMap, IdentityHashMap, WeakHashMap HashSet, LinkedHashSet, EnumSet, CopyOnWriteArraySetĪrrayList, LinkedList, CopyOnWriteArrayListĪrrayDeque, ConcurrentLinkedDeque, LinkedListĪrrayBlockingQueue, LinkedBlockingQueue, PriorityBlockingQueue, SynchronousQueue, DelayQueue For now, just look at the names and get a sense of what’s there descriptions are coming up very soon. Here are almost all of the classes, organized by the interfaces they implement (we’ve left out the crazy-specific ones, like JobStateReasons). Next, get a feel for the fact that there are quite a few implementations for each of the interfaces. Start by learning the names of following main interfaces (hang in there, well see descriptions later): The official documentation comes with some decent reads. Let’s get a big picture and look at a few examples.
So many collections come with the Java Core API. Blocking Some will block the current thread until an operation can be performed, others will throw an exception or return an error value immediately if an operation cannot be performed.
Thread safety Some will allow multiple threads to operate on the collection at the same time without interleaving sub-operations that would generate inconsistencies other provide no such guarantees.
Access Some restrict the access patterns, others allow arbitrary access. Mutability Some cannot have their elements updated, some can. Resizability Some can grow and shrink, some have a fixed size. Ordering Some are (internally) ordered, some are unordered. Uniqueness Some allow duplicate elements, some do not. Arrangement Some are arranged linearly (sequences), some hierarchically (trees), some without arrangement (sets), and some arbitrary arrangements (graphs). Before we look at specific collections, let’s take a minute to appreciate how wild the scope of variations is when it comes to collections: There a so many variations on how a collection’s elements are arranged, and what operations are allowed. What is a Collection?Ī collection is an object that holds a group of objects. As a serious and popular enterprise programming language, Java’s standard library has a huge number of interfaces and classes for collections.