2

I came across new list implementation which called GlueList

I want to know when i should use over ArrayList or LinkedList.

Ertuğrul Çetin
  • 5,131
  • 5
  • 37
  • 76
  • 2
    Same as any implementation A vs implementation B situation, really: when you have otherwise-working code, and you identify by profiling that ArrayList(/LinkedList) is a bottleneck which means you can't meet your desired specification, try using GlueList, and profile again. – Andy Turner Nov 16 '15 at 14:31
  • By “came across” you must mean that you implemented it (for other readers: a linked list/array list hybrid). – Guildenstern Feb 23 '21 at 19:37

1 Answers1

2

To be honest, if you cant decide after reading info at GlueList which states in few sentences why it is better (different) and even have benchmark to see the real values and also Big-O notation - you are not in position where you have to think about use "as effective as possible" list.

If you are not sure what to use, this rule is good enough :

Do I need to select items often based on their position like in array? Then use ArrayList.

Do I need add/remove items often in middle of array? Use LinkedList

PS : I did not use LinkedList for a long time, in most "usual" cases the ArrayList is better.

libik
  • 22,239
  • 9
  • 44
  • 87
  • Does anyone knows a practical scenario from real-world where frequent add/remove items in the middle of the list is required? – Tarun Feb 12 '19 at 05:00
  • 2
    @Tarun I cannot think about a case when anyone would like to add item in the middle of the list, but for the removal I can think of a case where you have to iterate over the items and remove them depending on some logic. For example if the list is an message inbox, then we may remove if sender is unknown, due to message expiration, etc. These are just some ideas from my imagination. – Bartosz Firyn Oct 28 '20 at 21:01