Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linked list class from scratch vs Default linked list class?

I've been writing my linked list data structure from scratch as a student for projects/assignments and I was wondering in the "real-world" does a developer have to write their own linked list DS or use any of the already provided linked list object in the Java docs. Which is better & in what scenario?

like image 289
ekeith Avatar asked Oct 28 '25 07:10

ekeith


1 Answers

A custom LinkedList implementation will very likely be more efficient because it allows you to make optimizations for your needs, however the JDK's LinkedList will always be preferable for its re-usability and maintainability benefits:

  1. Nobody will ever need to maintain the implementation of the LinkedList.
  2. Any future additions to the List interface will be automatically inherited.
  3. Developers reading your code will immediately understand what is going on.
  4. The Collections API has a ton of useful utility methods that will become available.
  5. Your LinkedList will be compatible with many third-party libraries which use List.

If you do decide to create a custom List implementation, you may choose to extend AbstractSequentialList in order to gain the benefits of #2, #4, and possibly #5.

like image 191
4castle Avatar answered Oct 29 '25 22:10

4castle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!