Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
Backed collections, like the ones you get from SortedSet's headSet(), subSet() and tailSet() methods, or SortedMap's headMap(), subMap(), and tailMap()'s methods, are intented as views of a particular section of the larger collection - according to their API documentation. These view collections are conceptually similar to updatable database views, and offer some of the same advantages. Their memory footprint is small, because no data is actually duplicated, as all references point to the same objects, and they can logically partition a large collection making it easier to work with relevant data. A "write-through" view isn't always what you want, though, so it's very important to be aware of that behavior. Some times you actually need a defensive copy of a collection, and directly exposing the results of the methods mentioned earlier would of course violate that. Another kind of backing is what you get when using Arrays.asList() where the returned List is backed by an array.
21st Mar 2017, 8:51 PM
saeed
saeed - avatar