Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preferred usage of ObjectArrayList over ArrayList

Tags:

java

fastutil

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?

like image 458
abhijit Avatar asked Apr 19 '26 03:04

abhijit


1 Answers

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.

like image 194
shinjw Avatar answered Apr 21 '26 16:04

shinjw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!