title: Is it safe for a method to return a Stream<T>?
body: <p>I have a situation where I am reading a database and returning a <code>List&lt;String&gt;</code>, where each string is selected and added to the list according to some criteria. The method signature is:</p>
  
  <pre><code>public List&lt;String&gt; myMethod(String query, int limit)
  </code></pre>
  
  <p>The second parameter provides an upper bound on the size of the returned list (setting <code>limit=-1</code> will remove any size restriction). To avoid making this method memory-intensive, I have written an equivalent method that returns <code>Stream&lt;String&gt;</code> instead of a list. ( <em>Note: I don't need random access to the returned elements or any other list-specific functionality.</em> )</p>
  
  <p>However, I am a bit skeptical about returning a <code>Stream&lt;&gt;</code>, especially since the method is public. Is it safe to have a public method returning a <code>Stream&lt;&gt;</code> in Java?</p>