title: Comparing two strings by character in java
body: <p>I have 2 strings :</p>
  
  <ul>
  <li><p>first= "BSNLP" </p></li>
  <li><p>second = "PBN" (or anything that user enters). </p></li>
  </ul>
  
  <p>Requirement is , O/P should return me the string with only those characters in first but not in second.
  Eg. in this case O/P is SL </p>
  
  <p>Eg2. </p>
  
  <ul>
  <li>first = "ASDR" </li>
  <li>second = "MRT" </li>
  </ul>
  
  <p>, o/p = "ASD"</p>
  
  <p>For this, the coding I have developed:</p>
  
  <pre><code>String one = "pnlm";
  String two ="bsnl";
  String fin = "";
  
  for(int i =0; i&lt;one.length();i++)
          {
              for(int j=0;j&lt;two.length();j++)
              {
  
                  //System.out.print(" "+two.charAt(j));
  
                  if(one.charAt(i) == two.charAt(j))
                  {
                      fin+=one.charAt(i);
  
                  }
  
              }
  
          }
  
  ch=removeDuplicates(fin);
          System.out.print(" Ret ::"+fin);
  
          System.out.println("\n Val ::"+ch);
  </code></pre>
  
  <p>CH gives me the string with equal characters, but using this logic i cant get the unequal characters.</p>
  
  <p>Can anyone please help?</p>