This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
In linked list data is stored in nodes that have reference to the previous node and the next node so adding element
is simple as creating the node an updating the next pointer on the last node and the previous pointer on the new
node. so Addition and Deletion in linked list is fast
Ravi Pavan wrote:
how data is added in a ArrayList .
I am assuming that you mean how does the arraylist add an element into the array that it is using internally to hold the elements.... Basically, elements are moved in the array. To insert into location N, the elements at N to the logical end is moved by one, so that the new element can be inserted.
If moving the elements will cause an overflow, then a new (array) is created, and the elements are copied to the new array.
Try to code your own class of ArrayList (I'm not saying that you should use it - just code for fun and to know how the ArrayList class could work). Use in it a generic array (like T). When you add something, you create a new generic array with the size plus one. When you remove an element, you can adjust the size and the elements of the array (not creating a new one) and keep an index pointer.
If that's not the right way to code a new array class, why don't you try to look to the source code of ArrayList.java?