title: stop the Twitter stream and return List of status with twitter4j
body: <p>Using the code example provided by Twitter4j, I'd like t stop the stream after a list of 1,000 status have been collected, and return this list. How can I do that?</p>
  
  <pre><code>public class Stream {
      public List&lt;Status&gt; execute throws TwitterException {
  
      List&lt;Status&gt; statuses = new ArrayList();
  
      ConfigurationBuilder cb = new ConfigurationBuilder();
      cb.setDebugEnabled(true);
      cb.setOAuthConsumerKey("bbb");
      cb.setOAuthConsumerSecret("bbb");
      cb.setOAuthAccessToken("bbb");
      cb.setOAuthAccessTokenSecret("bbb");
  
      TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
  
      StatusListener listener = new StatusListener() {
  
          public void onStatus(Status status) {
              statuses.add(status);
              if (statuses.size&gt;1000){
                //return statuses. Obviously that's not the correct place for a return statement...
              }
          }
  
          public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
              System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
          }
  
          public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
              System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
          }
  
          public void onScrubGeo(long userId, long upToStatusId) {
              System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
          }
  
          public void onException(Exception ex) {
              ex.printStackTrace();
          }
      };
  
      FilterQuery fq = new FilterQuery();
      String keywords[] = {"Keyword 1", "Keyword 2"};
  
      fq.track(keywords);
  
      twitterStream.addListener(listener);
      twitterStream.filter(fq);
  
  }
  </code></pre>