Monday, February 4, 2019

Data Structures

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
  1. ArrayList internally uses a dynamic array to store the elements.
  2. 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.
  3. An ArrayList class can act as a list only because it implements List only.
  4. ArrayList is better for storing and accessing data.
  5. Resize operation involves creating a new array and copying content from old to new array.
Linked List
  1. LinkedList internally uses a doubly linked list to store the elements.
  2. Manipulation with LinkedList is faster than ArrayList because it uses a doubly linked list, so no bit shifting is required in memory.
  3. LinkedList class can act as a list and queue both because it implements List and Deque interfaces.
  4. LinkedList is better for manipulating data.
Q What is the difference between Array and Array?

Array
  1. Array is fixed Length Data Structure.
  2. Length Cannot be changed once created in Java
  3. We cannot use Generics along with array.It can hold elements of a type only.
  4. Length() method is used to calculate size.
  5. Primitive types can be stored in Array.
Array List
  1. ArrayList is a variable length Collection Class.
  2. ArrayList can resize itself when gets full depending upon capacity and load factor.
  3. ArrayList allows type safety.
  4. Size() method is used to calculate size.
  5. 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.

No comments:

Post a Comment