Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Arrays - Do each element in array hold pointer to the next element

Tags:

java

arrays

stack

Java LinkedList class uses doubly linked list to store the elements.

Does Arrays in Java use singly-linked list ?

Is this how array and stacks are different in java.

like image 662
user2048204 Avatar asked Feb 08 '23 19:02

user2048204


2 Answers

No. An array is just a contiguous block of memory, with a length that can be checked to make sure you don't try to access elements outside the array's bounds.

To get to a specific element, the VM just (logically, at least) takes the start address of the data in the array, and adds the index multiplied by the element size.

like image 200
Jon Skeet Avatar answered Feb 11 '23 00:02

Jon Skeet


STACK follows LIFO. Thus the item that is first entered would be the last removed.

In array the items can be entered or removed in any order. Basically each member access is done using index. No strict order is to be followed here to remove a particular element.

see this link

like image 42
KVK Avatar answered Feb 11 '23 00:02

KVK