When a person decide to travel, he keeps thinking ! !
what will i take, which bag will suits my luggage ??
Collection is our bag, container that we staff our objects in. So which ?
for an arrayList removing an element from the middle of an array is expensive "require to move up all elements beyond the removed one".
linked list saved the day, since array stores object reference in consecutive memory location, linked list stores each object in a separate link, each link stores reference to next link.
however, for linkedList.get(index) result in starting from the first till reach the index "much overhead with each look up, starts again from the beginning ". have to trade off
However, when looking for a particular element "Search: require visiting all elements till find match" use hashMap faster but have no control over the order.
what will i take, which bag will suits my luggage ??
Collection is our bag, container that we staff our objects in. So which ?
for an arrayList removing an element from the middle of an array is expensive "require to move up all elements beyond the removed one".
linked list saved the day, since array stores object reference in consecutive memory location, linked list stores each object in a separate link, each link stores reference to next link.
however, for linkedList.get(index) result in starting from the first till reach the index "much overhead with each look up, starts again from the beginning ". have to trade off
However, when looking for a particular element "Search: require visiting all elements till find match" use hashMap faster but have no control over the order.
Comments
Post a Comment