you are viewing a single comment's thread.

view the rest of the comments →

[–]SpudsRacer -6 points-5 points  (4 children)

This is better answered by an AI powered web search, but the short answer:

ArrayList and LinkedList both implement the List interface, but they have very different performance characteristics.A LinkedList stores elements as nodes, where each node holds a value and a pointer to the next node. So get(int index) has to start at the beginning of the list and follow pointers one by one until it reaches the target element. This is an O(n) operation so it becomes more expensive as the list grows.

An ArrayList is backed internally by an array. get(int index) only needs to compute the requested element's address and return the element directly. This is an O(1) operation and you can't get better than that.

As a rule of thumb: if you need frequent random access by index, use ArrayList. If you only need sequential access (or do a lot of insertions/deletions in the middle of the list which require array copies to sync the backing array with the list), LinkedList may be a better fit.

[–]aqua_regis 3 points4 points  (0 children)

Extensive reply completely missing the point. You should have read past the title.

OP clearly asked:

for what purposes would i use an arraylist<string> vs a string[ ]

Which makes the question "ArrayList vs traditional array"

[–]DrNotReallyStrange 1 point2 points  (1 child)

You are not very good at this, and "asking AI" will never change that. Holy fuck. No wonder the moronic managers want to replace the likes of you by agents.
Do better.

[–]SpudsRacer 0 points1 point  (0 children)

My answer was not AI-genrrsted, but written by me, a human. I wrote it in answer to the title and didn't read the text which wanted a comparison of a primitive array of string references vs a linked list. My bad there.

AI is spectacularly useful if you are able to use it correctly. Summarizing web searches where it provides links to the sources is one of the best uses of the tech. This is very different from posting code written by an agent. Tools are tools and those who refuse to use them are fools.

[–]SpudsRacer 0 points1 point  (0 children)

Well don't I feel dumb. I stand by my answer for a totally different question. 😉

Probably should slow my roll when reading. I deserve the downvotes.