What is Java Collections Framework?
- Details
- Written by Nam Ha Minh
- Last Updated on 15 June 2016   |   Print Email
Data Structures + Algorithms = Programs
That means a computer program is a combination of data structures that hold information in an organized manner, along with algorithms which process the information to produce desired results or outputs.In any software programs, data structures and algorithms are the fundamental and primary elements that make them functioning.If you studied computer engineering in college, you are probably familiar with the concepts of data structures like linked list, queue, stack, tree, etc. And remember you were given exercises to implement these data structures using C/C++ programming languages?In the Java programming language, exactly in the JDK, you don’t have to re-invent the wheel, i.e. implementing data structures and algorithms from scratch, as the JDK provides a powerful, high quality and high performance reusable data structures and algorithms in a so-called Java Collections Framework.1. What is a Collection?
In terms of programming, a collection is a data structure that holds a set of objects in a specific manner. It looks like arrays but collections are more advanced and more flexible. An array simply stores a fixed number of objects, whereas a collection stores objects dynamically, i.e. you can add or remove objects as you wish.A collection also provides useful operations such as adding, removing, retrieving objects.2. What is Java Collections Framework?
3. Why Use Java Collections Framework?
The Java Collections Framework is a standard API which is used extensively in Java programming. It’s the standard and perfect API for manipulating collections because of the following primary benefits:- Reduce programming effort: with the reusable and useful data structures and algorithms, the programmers do not have to re-invent the wheel, thus they can devote their time on developing application’s business.
- Increase program speed and quality: the concrete collections implemented by Java Collections Framework are built for high performance and high quality, thus programmers can take this advantage into their programs.
- Foster software reuse: due to the Java Collections Framework is built into the JDK, code written using collections framework can be re-used every where among applications, libraries and APIs. That cuts development cost and increases interoperability among Java programs.
4. How to Use Java Collections Framework?
The Java Collections Framework is easy to learn and use. Here’s an example of using a List collection:List numbers = new ArrayList(); numbers.add(new Integer(1)); numbers.add(new Integer(5));This code adds two integer numbers into a list collection. However, that’s the old fashion code which is before Java 1.5. Now everyone is using collections with generics like this:
List<Integer> numbers = new ArrayList<>(); numbers.add(1); numbers.add(5);For your convenience, here are some official and useful resources that help you study the Java Collections Framework:
- Trail: Collections in the Java Tutorials: this is the most comprehensive and details guide about Java collections framework which is published by Oracle - the steward of Java technology. You should read this tutorial at least one time in your life, as I highly recommend.
- Java Collections API Reference: this is the API documentation that allows you to quickly consult any interfaces, classes and methods of the Collections Framework. And you will have to use this resource in your daily coding.
- And here are my tutorials on CodeJava.net for Java Collections framework: this gives you practical examples and useful tips for using collections and generics.
Complete Collections Tutorials:
- Java List Collection Tutorial and Examples
- Java Set Collection Tutorial and Examples
- Java Map Collection Tutorial and Examples
- Java Queue Collection Tutorial and Examples
Comments