Well, this one liner might qualify (uses Guava Ranges)
ContiguousSet<Integer> integerList = ContiguousSet.create(Range.closedOpen(0, 10), DiscreteDomain.integers());
System.out.println(integerList);
This doesn't create a List<Integer>
, but ContiguousSet
offers much the same functionality, in particular implementing Iterable<Integer>
which allows foreach
implementation in the same way as List<Integer>
.
In older versions (somewhere before Guava 14) you could use this:
ImmutableList<Integer> integerList = Ranges.closedOpen(0, 10).asSet(DiscreteDomains.integers()).asList();
System.out.println(integerList);
Both produce:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]