[英]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.