• Software
  • Leadership
  • Agile
  • Events
  • Other Topics
    • Finance
    • Robotics & AI
    • System Administration
    • Books
    • Life Experiences
    • Environment
  • Write and Earn
  • About Us
    • About Us
    • Our Contributors
    • Contact Us
    • Article Submission Guidelines
    • Logo demystified
  • Follow @MeJaneve
    Janeve.Me
  • Categories

    Browse through following categories for articles written by professionals.
    • Agile
      4
    • Books
      5
    • Environment
      1
    • Events and Conferences
      7
    • Featured
      15
    • Finance
      1
    • Leadership
      5
    • Life Experiences
      8
    • Software
      30
    • System Administration
      2
  • Software
  • Leadership
  • Agile
  • Events
  • Other Topics
    • Finance
    • Robotics & AI
    • System Administration
    • Books
    • Life Experiences
    • Environment
  • Write and Earn
  • About Us
    • About Us
    • Our Contributors
    • Contact Us
    • Article Submission Guidelines
    • Logo demystified
Home » Featured Software

Which Java collection to use?

Janeve George Posted On February 27, 2012
0
12.4K Views


0
Shares
  • Share On Facebook
  • Tweet It

Introduction

Java collections are one of the most commonly used data-structures by all Java professionals. But are you using the right collection class that would best suit your need? Most programmers usually use Vectors, ArrayList, HashMap, or Hashtable. There are many other collection classes available with the JDK that you can use instead of re-inventing logic to suit your needs.

We will be trying to understand the different types of classes and when each Collection class could be used. We wouldn’t be looking into the implementation details of any collection, for that please refer to the latest Java Collection API docs.

The Core Collection Framework Interfaces

The core collection frameworks are depicted in the following image.

Java Collection Interfaces

Java Collection Interfaces

The main type of collections are:

  1. Sets
  2. Lists
  3. Queues
  4. Maps

Maps are not an integral part of the Collection framework, but they are still considered as Collection because of their capability to store and manipulate data as a collection of objects.

Sorted Sets and Sorted Maps are basically a sorted version of Sets and Maps.

Factors that could help on deciding a Collection

There are various factors that can be considered when selecting an appropriate collection for a particular problem. These factors are:

  1. Ordering – Some sort of ordering in the elements. For example, sorted order, insertion order, or no specific ordering.
  2. Duplicates – May or may not want to allow duplicate elements in a collection.
  3. Thread Safe – Ensure the safety of the elements in a collection in case there are multiple threads accessing it.
  4. Key-Value pair – Store in key-value pairs.
  5. Blocking operations – Wait for the collection to become non-empty when retrieving an element.
  6. Random Access – Instant retrieval of an element.
  7. Upper Bounds – To limit the maximum number of elements a collection can hold.

There are also other factors like priority, delay, etc..

Java Collection Matrix

The following matrix will help in deciding which Java Collection Class would best fit your requirement. Please note that in the case of Key-Value based collection I have considered the factors only for the key and ignored the value in this section.

Click here to download the matrix shown below.

Java-Collection-Matrix-Java-Collection-Matrix

Post Views: 12,408
0
Shares
  • Share On Facebook
  • Tweet It




Author

Janeve George

A Technology Leader, Software Engineer, and Agile Methodologies enthusiast. Currently, working as Lead Software Development with Zeta Suite. He has more than 1.6 decades of experience spanning different verticals predominated by hosting, cloud, and media delivery technologies.

Class.forName() and DriverManager.getConnection()
Read Next

Class.forName() and DriverManager.getConnection()

  • Follow @MeJaneve
    Janeve.Me
  • Categories

    Browse through following categories for articles written by professionals.
    • Agile
      4
    • Books
      5
    • Environment
      1
    • Events and Conferences
      7
    • Featured
      15
    • Finance
      1
    • Leadership
      5
    • Life Experiences
      8
    • Software
      30
    • System Administration
      2

  • Popular Posts

  • Recent Posts

    • Java Asynchronous Programming using CompletableFuture - Part 1
    • The Java Stream API
    • Functional Interfaces in Java
    • Online Webinar: Students & New Technology - 28th July 2020
  • Keep In Touch

    Follow us on social media to get latest articles on Programming, System Architecture, Agile Development Methodologies, Product and Project Management, Personal Development, BigData, Robotics, Upcoming Events and more...


Copyright © 2020 | Janeve.Me. All rights Reserved.
Press enter/return to begin your search