title: simplify java stream to return an error message
body: <p>Hi I am new to stream in java I am trying to find which item inside a file has more than 12 of length also if that item has letters mixed in it and wanted to know if this can be simplified using stream in java without using the forEach method in java stream:</p>
  <pre><code>Stream&lt;String&gt; stream = Files.lines(path)
  
  stream.forEach(item -&gt; {
        Pattern pattern = Pattern.compile(REGEX);
        Matcher matcher = pattern.matcher(item);
        if (item.length() &gt; 12) {
               log.error(&quot;Item must not exceed 12 numbers {}&quot;, item);
               streamMessage.set(&quot;Item must not exceed 12 numbers&quot;);
        }
        else if (matcher.matches()) {
               log.error(&quot;Invalid Item format {}&quot;, item);
               streamMessage.set(&quot;Invalid Item format&quot;);
        }
  });
  </code></pre>
  <p>I also need it to return the log.error messages and the stream message thank you</p>
  <p>EDIT:</p>
  <p>I have tried Glare storm's answer but the message being returned by this:</p>
  <pre><code>Stream&lt;String&gt; lengthStream =
                      stream.filter(item -&gt; item.length() &gt; 12);
  
  Pattern pattern = Pattern.compile(REGEX);
  
  Stream&lt;String&gt; letterStream =
                      lengthStream.filter(pattern.asPredicate());
  if(lengthStream != null){
         log.error(&quot;Item must not exceed 12 numbers&quot;);
         message = &quot;Item must not exceed 12 numbers&quot;;
  }
  if(letterStream != null){
         log.error(&quot;Invalid Item format&quot;);
         message = &quot;Invalid Item format&quot;;
  }
  </code></pre>
  <p>it always return Invalid Item format even tho there are no letters inside the file and only has exceeded 12 in length</p>