Java Interview Bootcamp by Sam Atkinson

Java Interview Bootcamp by Sam Atkinson

Author:Sam Atkinson [Atkinson, Sam]
Language: eng
Format: epub
Published: 2015-02-28T05:00:00+00:00


speed. How that speed is determined depends on the implementation. The important thing is to understand is the speed of the relative collection implementations to each other, and how that influences your selection.

Collection Implementations

Q: Why would I choose LinkedList over an ArrayList?

Q: Which is faster, TreeSet or HashSet?

Q: How does a LinkedList work?

The collection implementations tend to be based on either a Linked implementation, a Tree implementation or a H ash implementation. There are entire textbooks based on this, but what you need to know is how it affects your collection choices.

Linked implementation

Example: LinkedList, LinkedHashSet Under the covers, each item is held in a “node”.

Each node has a pointer to the next item in the collection like so.

What does this mean for speed?

When adding an item into a linked connection it’s quick, irrelevant of where you’re adding the node. If you have a list of 3 items and want to add a new one in position 1, the operation is simply to point position 2 to the new item, and the new item to the old position 2.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.