InfoQ Homepage   	  		  			  			                  News                 		  		Java's Collections Framework Gets a Makeover with New Sequenced Collec

Java's Collections Framework Gets a Makeover with New Sequenced Collection Types

submited by
Style Pass
2023-03-14 19:00:03

InfoQ Homepage News Java's Collections Framework Gets a Makeover with New Sequenced Collection Types

JEP 431: Sequenced Collections has been promoted from Candidate to Proposed to Target status for JDK 21. It proposes introducing "a new family of interfaces that represent the concept of a collection whose elements are arranged in a well-defined sequence or ordering, as a structural property of the collection." This is motivated by the need for a well-defined ordering and a uniform set of operations within the Collections Framework.

Java's collections framework has long needed a collection type that represents a sequence of elements with a defined encounter order and a uniform set of operations that apply across such collections. Unfortunately, support for encounter order is currently spread across the type hierarchy, making expressing certain practical concepts in APIs difficult. In response, a proposal has been proposed to introduce new interfaces to represent collections with a defined encounter order and provide uniform APIs for accessing their first and last elements and processing them in reverse order.

The lack of a collection type representing a sequence of elements with a defined encounter order has been a repeated source of problems and complaints. For example, while List and Deque define an encounter order, their common supertype is Collection, which does not. Similarly, Set does not specify an encounter order, and subtypes such as HashSet do not define one, but subtypes such as SortedSet and LinkedHashSet do.

Leave a Comment