trong Eclipse Collections, sau đây sẽ làm việc:
Set<Integer> set1 = Sets.mutable.of(1, 2, 3, 4, 5);
Set<Integer> set2 = Sets.mutable.of(new Integer[]{1, 2, 3, 4, 5});
MutableSet<Integer> mutableSet = Sets.mutable.of(1, 2, 3, 4, 5);
ImmutableSet<Integer> immutableSet = Sets.immutable.of(1, 2, 3, 4, 5);
Set<Integer> unmodifiableSet = Sets.mutable.of(1, 2, 3, 4, 5).asUnmodifiable();
Set<Integer> synchronizedSet = Sets.mutable.of(1, 2, 3, 4, 5).asSynchronized();
ImmutableSet<Integer> immutableSet = Sets.mutable.of(1, 2, 3, 4, 5).toImmutable();
Lưu ý: Tôi là một người có duyên cho Bộ sưu tập Eclipse
Nguồn
2012-12-18 23:04:29
Tôi sẽ để lại cuối cùng, nếu không thì tốt đẹp oneliner! –
despot
điều này rất cao. Tại sao tạo một danh sách để lặp lại nó để tạo ra một bộ? Chỉ cần lặp lại chính mảng đó. – dataoz
@dataoz: Sai; 'Arrays.asList' là O (1). – SLaks