Q What is the difference between Array List and Linked List?
Array List and Linked List both extend the List interface which extends Collection interface.
Here are the differences between them :
Array List
Array List and Linked List both extend the List interface which extends Collection interface.
Here are the differences between them :
Array List
- ArrayList internally uses a dynamic array to store the elements.
- Manipulation with ArrayList is slow because it internally uses an array. If any element is removed from the array, all the bits are shifted in memory.
- An ArrayList class can act as a list only because it implements List only.
- ArrayList is better for storing and accessing data.
- Resize operation involves creating a new array and copying content from old to new array.
- LinkedList internally uses a doubly linked list to store the elements.
- Manipulation with LinkedList is faster than ArrayList because it uses a doubly linked list, so no bit shifting is required in memory.
- LinkedList class can act as a list and queue both because it implements List and Deque interfaces.
- LinkedList is better for manipulating data.
Q What is the difference between Array and Array?
Array
- Array is fixed Length Data Structure.
- Length Cannot be changed once created in Java
- We cannot use Generics along with array.It can hold elements of a type only.
- Length() method is used to calculate size.
- Primitive types can be stored in Array.
Array List
- ArrayList is a variable length Collection Class.
- ArrayList can resize itself when gets full depending upon capacity and load factor.
- ArrayList allows type safety.
- Size() method is used to calculate size.
- We can only store objects in Array List.All primitive types are converted to objects of their Wrapper class before storing to Array List this is called as auto boxing.
Q What is the difference between data member length; and member function length();?
Data member length is used to find length of an array where as Member function length(); is used to find length of a String.
Data member length is used to find length of an array where as Member function length(); is used to find length of a String.
No comments:
Post a Comment