First off, you didn’t tell us what data structure you are working with. So, I’ll go with the assumption that you are using Vector
or some Vector
derivative.
The two methods are identical according to the documentation:
http://download.oracle.com/javase/1,5.0/docs/api/java/util/Vector.html
That being said however, elementAt(idx)
, dates back to the days when Vector did not follow the List patterns (by extending AbstractList
) — if you read the full docs you’ll see that Vector was modified to implement the List interfaces.
Therefore, I would expect get(idx)
to provide the fastest speeds, and elementAt(idx)
to simply call through to get(idx)
. At any rate, the difference in speed is going to be almost nothing — and you should look elsewhere if you’re looking to get a performance bump.
1
solved get() or elementAt() in Java [closed]