Posts

Showing posts with the label SequencedCollection

Sequenced Collections, Look before you leap

 I have been giving myself a refresher on Java Collections APIs as part of preparation for coding interviews. It's not all reading dry documentation, as we now have podcasts, youtube videos and all manner of consumable media available to consume. On one particular podcast episode I heard about Sequenced Collections, which was something that was introduced with Java 21 a couple of years ago. An example of some functionality introduced by Sequenced Collections is the option to obtain a reversed view of a collection. The key word to pay attention to there is, "view". So, if we take an ArrayList and call reversed()   what we get back will be a SequencedCollection of the original ArrayList. As part of the SequencedCollection we can then call addLast(e) to add the specified object, e, onto the end of the collection. The gotcha If the ArrayList contains many objects then we will be faced with the performance overhead of adjusting the location offset of each individual existing e...