Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 变换范围的标准方法是什么<;T>;进入列表<;T>;?_Java_Collections_Guava - Fatal编程技术网

Java 变换范围的标准方法是什么<;T>;进入列表<;T>;?

Java 变换范围的标准方法是什么<;T>;进入列表<;T>;?,java,collections,guava,Java,Collections,Guava,有几个选择,但我不确定哪一个是标准的 手动从下限迭代到上限 连续集 还有别的吗 这不是那么简单,但当然是可能的。只需创建,这是一个,并使用方法,例如: Range=Range.closed(1,5); ContiguousSet-ourIntegers=ContiguousSet.create(范围,离散域.integers()); ImmutableList-ourIntegersList=ourIntegers.asList(); System.out.println(ourInteger

有几个选择,但我不确定哪一个是标准的

  • 手动从下限迭代到上限
  • 连续集
  • 还有别的吗

    • 这不是那么简单,但当然是可能的。只需创建,这是一个,并使用方法,例如:

      Range=Range.closed(1,5);
      ContiguousSet-ourIntegers=ContiguousSet.create(范围,离散域.integers());
      ImmutableList-ourIntegersList=ourIntegers.asList();
      System.out.println(ourIntegers);//[1‥5]
      System.out.println(ourIntegersList);//[1, 2, 3, 4, 5]
      
      请注意,您可能希望坚持使用
      ContiguousSet
      (与使用列表视图相比),因为
      前者实际上并不将每个元素存储在内存中,而后者则存储在内存中,这可能是一个大范围的问题。

      @PatrickParker它在Google collections Library中,只要你在番石榴世界,并且你的范围有一个定义的域,那么ContiguousSet似乎就是一条出路。。。不知道你说的“规范”是什么意思
      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]