Java Experience – Time complexity of collection classes
The Java collection classes have different time complexity for each of the operations. While ArrayList can given you index based access in order, HashMap can give you key value pair storage without any ordering. TreeSet and TreeMap provide sorted order of elements present in them. Similarly for remove operation, one collection class may work better than the other due to the underlying structure of the class. Here is a ready reference for O(n) complexity of various commonly used Java collection classes.
Please note that for some of the collections which are ordered, time complexity has been shown for insertion/deletion in the beginning, middle and at the end. The complexity can be used as a criteria for using a collection class when multiple classes deem suitable for a purpose.
Read full article from Java Experience – Time complexity of collection classes
No comments:
Post a Comment