[英]What is the canonical way to transform a Range<T> into a List<T>?
有幾種選擇,但是我不確定哪個是標准的。
這不是那么簡單,但是當然可以。 只需創建ContiguousSet<T>
(它是一個ImmutableSortedSet
,然后使用方法asList()
,例如:
Range<Integer> range = Range.closed(1, 5);
ContiguousSet<Integer> ourIntegers = ContiguousSet.create(range, DiscreteDomain.integers());
ImmutableList<Integer> ourIntegersList = ourIntegers.asList();
System.out.println(ourIntegers); // [1‥5]
System.out.println(ourIntegersList); // [1, 2, 3, 4, 5]
請注意,您可能要堅持使用ContiguousSet
(與使用列表視圖相比),因為前者實際上並沒有將每個元素存儲在內存中,而后者確實存在,這可能是大范圍的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.