r/javahelp • • Apr 30 '20

ArrayList vs LinkedList

So I understand that for different situations, either the ArrayList API or the LinkedList API will be more efficient. So what should I look for in terms of design that will tell me which one of those structures is recommended? Is it more related to preference rather than specific uses?

Thanks!

17 Upvotes

22 comments sorted by

View all comments

1

u/LouGarret76 May 01 '20

Well, As far as I know arraylist in java does not keep the sequence in which you add the items. LinkedList does. So if you want to read the items in the order you add them this is almost impossible with arraylist.

This is a key difference in my opinion.

1

u/nutrecht Lead Software Engineer / EU / 20+ YXP May 01 '20

Well, As far as I know arraylist in java does not keep the sequence in which you add the items.

That's plain wrong. You're confusing Sets with Lists.

1

u/LouGarret76 May 01 '20

You are correct. It looks like this is no longer the case in the current implementation of openjdk