&gt; As below, let&#x27;s produce a sequence of the form [true false false true true true false false false false ...] of exact length 1000 without computing any more than exactly 1000 elements.<p>So, again, python:<p><pre><code>  [i % 2 == 0 for i in range(1000)]
</code></pre>
(If you insist on Java, its fairly straightforward, though not a one-liner AFAIK, using Java 8 generators.)