Java collections framework: Difference between revisions

Content deleted Content added
Add in-line citation for AbstractSet
Add information on CopyOnWriteArrayList
Line 103:
 
===List implementations===
There are several concrete classes that implement <code>List</code>, including {{java|AbstractList}} and all of its corresponding subclasses, andas well as {{java|CopyOnWriteArrayList}}.
 
====AbstractList class====
Line 124:
 
The <code>Stack</code> class represents a last-in-first-out (LIFO) stack of objects. The Stack class has five additional operations that allow a <code>Vector</code> to be treated as a <code>Stack</code>. The usual {{Javadoc:SE|module=java.base|name=push(E e)|java/util|Stack|push(E)}} and {{Javadoc:SE|module=java.base|name=pop()|java/util|Stack|pop()}} operations are provided, as well as a method ({{Javadoc:SE|module=java.base|name=peek()|java/util|Stack|peek()}}) to peek at the top item on the <code>Stack</code>, a method to test for whether the <code>Stack</code> is empty ({{Javadoc:SE|module=java.base|name=empty()|java/util|Stack|empty()}}), and a method to search the <code>Stack</code> for an item and discover how far it is from the top ({{Javadoc:SE|module=java.base|name=search(Object o)|java/util|Stack|search(java.lang.Object)}}). When a <code>Stack</code> is first created, it contains no items.
 
====CopyOnWriteArrayList class====
The {{code|CopyOnWriteArrayList}} extends the {{code|Object}} class, and does not extend any other classes. {{code|CopyOnWriteArrayList}} allows for thread-safety without performing excessive synchronization.
 
In some scenarios, synchronization is mandatory. For example, if a method modifies a static field, and the method must be called by multiple threads, then synchronization is mandatory and concurrency utilities such as {{code|CopyOnWriteArrayList}} should not be used.
 
However synchronization can incur a performance overhead. For scenarios where synchronization is not mandatory, then the {{code|CopyOnWriteArrayList}} is a viable, thread-safe alternative to synchronization that leverages [[Multi-core processor]]s and results in higher [[Central processing unit|CPU]] utilization.
{{sfn|Bloch|2018|loc=Chapter §11 Item 79: Avoid excessive synchronization|pp=317-322}}
 
 
==Queue interfaces==