title: Using Lambda expression to replace chars in string using HashMap
body: <p>So i'm working on a project in which I have to convert a String containing greek letters in to a string containing the english representation for this letter. So a greek <code>α</code> would become <code>alpha</code> and <code>Α</code> would become <code>Alpha</code>.</p>
  
  <p>I have created a HashMap which has the appropriate conversions from Unicode Character to a normal String.</p>
  
  <p>I have used a simple <code>For</code> loop to check if a <code>Char</code> in the input <code>String</code> is a <code>Key</code> in the <code>HashMap</code> and if it is then i'll append its replacement using a <code>StringBuilder</code>. Here is the code I use to do this:</p>
  
  <pre><code>char[] ca = snippet.toCharArray();
          StringBuilder out = new StringBuilder();
          for (char c : ca) {
              if (GREEK_LETTER_DICT.containsKey(Character.toString(c))) {
                  out.append( GREEK_LETTER_DICT.get(Character.toString(c)));
              } else {
                  out.append(c);
              }
          }
      return out.toString();
  </code></pre>
  
  <p>This is in a public static method with <code>String</code> as input.
  The thing I want to know is if it is possible to do the same with a lambda expression? I have already found a couple of solutions replacing a <code>Character</code> in <code>String</code> but they do not use a <code>HashMap</code>/<code>Dictionary</code>.</p>
  
  <p>I understand that it is completely useless to just convert this into a lambda expression for the sake of using a lambda expression, but because I have another 7 of these functions shortening my code by almost 60% I would like to see if it is at all possible to do this in "one line" of code. This way i can decrease the number of separate methods I use and get cleaner code.</p>
  
  <p>So far I have found a way to convert a <code>String</code> to a <code>Stream</code> using:</p>
  
  <pre><code>String.chars()
  </code></pre>
  
  <p>Then converting this <code>IntStream</code> to a <code>Stream&lt;Character&gt;</code> with</p>
  
  <pre><code>.mapToObj(ch -&gt; (char) ch)
  </code></pre>
  
  <p>and filtering to see if the <code>Character</code> is in the <code>HashMap</code> with</p>
  
  <pre><code>.filter(ch -&gt; (GREEK_LETTER_DICT.containsKey(ch)))
  </code></pre>
  
  <p>The problem lies in the fact that I am not able to</p>
  
  <ol>
  <li>append the original <code>Character</code> to the output <code>String</code> if it is not in the <code>HashMap</code></li>
  <li>replace the <code>Character</code> with the String in the <code>HashMap</code></li>
  </ol>
  
  <p>So any help on these two points is appreciated. I found out that sometimes I think the wrong way around because instead of seeing if a <code>Character</code> in a <code>String</code> is equal to a <code>Character</code> in a list of options, I should have checked if that list of options returns a positive <code>index</code>. So this (PseudeoCode):</p>
  
  <p><code>"StringWithOptions".indexOf('characterLiteral')</code></p>
  
  <p>instead of this:</p>
  
  <p><code>Character.equals("One|of|these")</code></p>