title: Is it possible to get next element in the Stream?
body: <p>I am trying to converting a <code>for loop</code> to functional code. I need to look ahead one value and also look behind one value. Is it possible using streams?
  The following code is to convert the Roman text to numeric value.
  Not sure if reduce method with two/three arguments can help here.</p>
  <pre><code>int previousCharValue = 0;
  int total = 0;
      
  for (int i = 0; i &lt; input.length(); i++) {
      char current = input.charAt(i);
          
      RomanNumeral romanNum = RomanNumeral.valueOf(Character.toString(current));
          
      if (previousCharValue &gt; 0) { 
          total += (romanNum.getNumericValue() - previousCharValue);
          previousCharValue = 0;
      } else {
          if (i &lt; input.length() - 1) {
          
              char next = input.charAt(i + 1);
              RomanNumeral nextNum = RomanNumeral.valueOf(Character.toString(next));
              if (romanNum.getNumericValue() &lt; nextNum.getNumericValue()) {
                  previousCharValue = romanNum.getNumericValue();
              }
          }
          if (previousCharValue == 0) {
              total += romanNum.getNumericValue();
          }
              
      }
          
  }
  </code></pre>