abhijit
abhijit

Reputation: 385

Preferred usage of ObjectArrayList over ArrayList

I am very new to Java. I have recently come across fastutil and found ObjectArrayList class.

Is there any difference in performance if ObjectArrayList is used instead of ArrayList? What are the use cases for using ObjectArrayList?

Upvotes: 3

Views: 1596

Answers (2)

shinjw
shinjw

Reputation: 3431

According to fastutil documentation

A type-specific array-based list; provides some additional methods that use polymorphism to avoid (un)boxing.

There is a performance benefit to fastutil's implementation in cases where (un)boxing takes place.

The ObjectArrayList is backed by a generic type array. Whereas an ArrayList is backed by Object[] Really the performance between the two would be nominal. However FWIW, looks like this library provides primitive backed arrays IntArrayList DoubleArrayList where these boxing claims would actually see visible benefits in large datasets.

However, if you're new to Java. I'd highly recommend getting familiar with java.util.ArrayList before seeking out other variants.In most cases, taking the standard outweighs the performance benefit.

Upvotes: 5

Raymond Mutyaba
Raymond Mutyaba

Reputation: 950

You should not be concerned with performance when you start learning a new language. Focus on the basics. Write code that runs, and then write code that is useful. Speed and efficiency only matters when the code you write affects the world around you (such as writing code for work). Do not worry about fastutil and ObjectArrayList. Finish your application with ArrayList and if your app is too slow for you only then should you find something faster.

Upvotes: 0

Related Questions