Sitemap

Introducing Extended Collection Framework: Breaking Java’s Limits

3 min readApr 5, 2024

--

Have you ever thought how many max elements can a java collection object hold ? Well theoretically it can hold Integer.MAX_VALUE i.e 2147483647

Have you ever found a use case where your collection exceeds those limitations ? Does java handle such cases ? Theoretically No.

Note: Of course you might think this use case is impractical/rare or may be has performance considerations. However I would like to provide some insights to handle such rare use cases and benefits the below approach has over Java.

Refer GitHub repo for source code.

Get Shivakumar Sudanapelly’s stories in your inbox

Join Medium for free to get updates from this writer.

As I was going through this design and implementation (you will see below) found few other benefits and optimizations than java. Example List’s Add operation is optimized while resizing internal data structure.

Overview:

In the realm of Java programming, one of the long-standing challenges has been the limitation on the number of elements a collection can hold. Java, by default, restricts collections to Integer.MAX_VALUE elements. However, what if you need to work with a collection that exceeds this limit? Enter our custom collection framework, designed to shatter these constraints and provide a robust solution for handling massive data sets.

Addressing the Limitations

At the core of our collection framework is the concept of scalability. We recognized the need to go beyond Java’s imposed boundaries, especially when dealing with collections that demand capacities beyond Integer.MAX_VALUE. Our framework’s key innovation lies in setting the capacity of our collections to ~Long.MAX_VALUE, significantly expanding the scope of what Java collections can handle.

The 2D Internal Architecture: BackBone

To achieve this unprecedented scalability, we adopted a sophisticated 2D internal architecture. Unlike traditional single-dimensional arrays, which are limited by their maximum size, 2D arrays offer a more flexible and scalable approach. By leveraging 2D arrays, we can partition our collections into multiple arrays, each capable of accommodating up to ~Integer.MAX_VALUE elements.

Optimizing Operations

One of the critical advantages of our 2D internal architecture is its impact on operations like add, remove, and get. The add operation, in particular, benefits from this design, as it eliminates the need to traverse through all elements from previous rows in the 2D array. This optimized approach significantly enhances performance, especially when dealing with extensive collections.

Memory Considerations and Use Cases

It’s important to note that while our framework offers unprecedented scalability, this scalability comes with memory requirements. Managing collections of such magnitude necessitates a robust memory management strategy. Additionally, it’s essential to highlight that our framework caters to specific, rare use cases where traditional Java collections fall short.

Understand ExtendedArrayList (ArrayList version of java) Internal design

2D array internally used by ExtendedArrayList (new class) for handling large data sets
  1. When an object is created we use a 2D array to back the ArrayList data structure unlike java.
  2. In traditional Java collections, adding elements can become cumbersome as the collection size grows. However, with our 2D internal architecture, adding element finds a position in 2D array and resizes accordingly.
  3. Each row in 2D array represents chunk of data so users can achieve optimal operations with add. In traditional java ArrayList adding an element resizes and copy's whole elements as part of it. However with 2D array structure we don’t have to copy every element from previous rows, this will avoid computation and optimizes performance.
  4. Retrieving elements from our collection involves a unique approach. Internally, elements are indexed based on their row and column positions within the 2D array. This indexing mechanism ensures rapid access to elements, even within massive collections.

Conclusion

Idea of our custom collection framework is to empower developers to work with colossal data sets that were previously beyond reach. By harnessing the potential of 2D internal architecture, we can transcend Java’s limitations and ushered in a new era of scalability and performance.

I do not want to claim the open source framework on git hub is fully ready and can be used.

My main intention is to lay out the design approach and benefits with it to over come such use cases and help those who are in need.

Feel free to hit Github repo and contribute/fix if you have any.

--

--