filmov
tv
Differences between Arraylist vs Linkedlist Java Interview Questions | Vector vs Array | Code Decode
Показать описание
It covers live demo and in depth explanation of very frequently asked differences like Array VS ArrayList, ArrayList Vs Vector and ArrayList Vs LinkedList.
Udemy Course of Code Decode on Microservice k8s AWS CICD link:
Course Description Video :
Difference between Array and ArrayList.
Array is static in size.
ArrayList is dynamic in size. It can be resized itself when needed.
Array is a fixed length data structure
ArrayList is a variable length Collection class.
An array can store both objects and primitives type.
We cannot store primitive type in ArrayList. It automatically converts primitive type to object.
It performs fast in comparison to ArrayList because of fixed size.
resize() operation : Automatic resize will slow down the performance as it will use temporary array to copy elements from the old array to new array.(by 50%)
add() or get() operation : almost same performance , as for ArrayList object these operations run in constant time.
It is mandatory to provide the size of an array while initializing it directly or indirectly.
We can create an instance of ArrayList without specifying its size. Java creates ArrayList of default size.
We use for loop or for each loop to iterate over an array.
We can use an iterator also to iterate over ArrayList.
Array provides a length variable which denotes the length of an array.
ArrayList provides the size() method to determine the size of ArrayList.
Array can be multi-dimensional.
ArrayList is always single-dimensional.
the elements are contained in adjacent memory locations.
the objects are incapable of being contained in contiguous locations.
The assignment operator is put to use for the storage of elements.
The add() attribute is utilized for the insertion of elements in an ArrayList.
Generics are not compatible with Arrays.
ArrayLists allow the use of Generics.
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Difference between ArrayList and Vector
ArrayList is not synchronized.
Vector is synchronized.
Not Thread Safe
Thread Safe
ArrayList is fast because it is non-synchronized.
.
ArrayList increments 50% of current array size
Vector increments 100% means doubles the array size.
Iterating Values
.
------------------------------------------------------------------------------------------------------------------------------------------------
Difference between ArrayList and LinkedList
ArrayList internally uses a dynamic array to store its elements.
LinkedList uses Doubly Linked List to store its elements.
ArrayList implements only List.
LinkedList implements List as well as Queue. It can acts as a queue as well.
Manipulation with ArrayList is slow because it internally uses an array. If any element is removed from the array, all the other elements are shifted in memory.
LinkedList is slower than ArrayList in storing and accessing data as access requires node by node traversal.
there is no descendingIterator() in ArrayList
LinkedList can be iterated in reverse direction using descendingIterator()
If the constructor is not overloaded , then ArrayList creates an empty list of initial capacity 10
There is no case of default capacity in a LinkedList. Hence an empty list is created when a LinkedList is initialized.
In ArrayList Memory overhead is less as each index only holds the actual object(data).
Memory overhead in LinkedList is more as compared to ArrayList as node in LinkedList needs to maintain the addresses of next and previous node.
Subscriber and Follow Code Decode
#codedecode #javacollectioninterviewquestion #topjavacollectioninterveiwquestion #javainterviewquestion
Udemy Course of Code Decode on Microservice k8s AWS CICD link:
Course Description Video :
Difference between Array and ArrayList.
Array is static in size.
ArrayList is dynamic in size. It can be resized itself when needed.
Array is a fixed length data structure
ArrayList is a variable length Collection class.
An array can store both objects and primitives type.
We cannot store primitive type in ArrayList. It automatically converts primitive type to object.
It performs fast in comparison to ArrayList because of fixed size.
resize() operation : Automatic resize will slow down the performance as it will use temporary array to copy elements from the old array to new array.(by 50%)
add() or get() operation : almost same performance , as for ArrayList object these operations run in constant time.
It is mandatory to provide the size of an array while initializing it directly or indirectly.
We can create an instance of ArrayList without specifying its size. Java creates ArrayList of default size.
We use for loop or for each loop to iterate over an array.
We can use an iterator also to iterate over ArrayList.
Array provides a length variable which denotes the length of an array.
ArrayList provides the size() method to determine the size of ArrayList.
Array can be multi-dimensional.
ArrayList is always single-dimensional.
the elements are contained in adjacent memory locations.
the objects are incapable of being contained in contiguous locations.
The assignment operator is put to use for the storage of elements.
The add() attribute is utilized for the insertion of elements in an ArrayList.
Generics are not compatible with Arrays.
ArrayLists allow the use of Generics.
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Difference between ArrayList and Vector
ArrayList is not synchronized.
Vector is synchronized.
Not Thread Safe
Thread Safe
ArrayList is fast because it is non-synchronized.
.
ArrayList increments 50% of current array size
Vector increments 100% means doubles the array size.
Iterating Values
.
------------------------------------------------------------------------------------------------------------------------------------------------
Difference between ArrayList and LinkedList
ArrayList internally uses a dynamic array to store its elements.
LinkedList uses Doubly Linked List to store its elements.
ArrayList implements only List.
LinkedList implements List as well as Queue. It can acts as a queue as well.
Manipulation with ArrayList is slow because it internally uses an array. If any element is removed from the array, all the other elements are shifted in memory.
LinkedList is slower than ArrayList in storing and accessing data as access requires node by node traversal.
there is no descendingIterator() in ArrayList
LinkedList can be iterated in reverse direction using descendingIterator()
If the constructor is not overloaded , then ArrayList creates an empty list of initial capacity 10
There is no case of default capacity in a LinkedList. Hence an empty list is created when a LinkedList is initialized.
In ArrayList Memory overhead is less as each index only holds the actual object(data).
Memory overhead in LinkedList is more as compared to ArrayList as node in LinkedList needs to maintain the addresses of next and previous node.
Subscriber and Follow Code Decode
#codedecode #javacollectioninterviewquestion #topjavacollectioninterveiwquestion #javainterviewquestion
Комментарии