2011-09-19 13 views

답변

11

set 추상화는 traversable의 서브 클래스 인, 이내에 개최 요소의 순서에 대한 보장이 없기 때문에 :

A traversable class might or might not have two properties: strictness and orderedness. Neither is represented as a type. 
... 
If the class is not ordered, foreach can visit elements in different orders for different runs (but it will keep the same order in the same run).' 

더 정확하게 요소가 '엉망'얻을 이유에 대해 다음 toSet 방법은 구축을 일부 기존 컬렉션에서 새로 설정된 컬렉션. 이 새로운 집합 컬렉션에 대해 기본 집합 구현을 사용합니다. 기본 세트 구현은 해시 테이블을 기반으로합니다. 해시 테이블에서 요소의 순서는 정의되지 않습니다.

+3

요소의 고유성이 필요한 경우 'mutable.LinkedHashSet' 컬렉션이 있습니다. 그 안에있는 요소는 추가 된 순서대로 통과됩니다. – axel22