title: Detecting multiple instances of word with .contains
body: <p>I am trying to count the number of instances a certain string occurs within another string. The input string that I am searching is not formatted in any fashion. </p>
  
  <p>I am currently doing the below but it is obvious that it only counts .contains once. What is the most efficient way to count instances multiple times.</p>
  
  <pre><code> public String computeBestFitKey() {
      if(this.inputText == null)
          return null;
      String answer = null;
      int bestCount = 0, tempCount = 0;
      for(String s: logicTemplate.getLogicMap().keySet()) {
          String[] keyWords = this.logicTemplate.getKeyWords(s);
          for(String word: keyWords) {
              if(this.inputText.toLowerCase().contains(word.toLowerCase())) {
                  System.out.println("word found: "+word.toLowerCase());
                  tempCount++;
              }
          }
          if(tempCount &gt; bestCount) {
              bestCount = tempCount;
              answer = s;
  
          }
          tempCount = 0;
      }
      return answer;
  }
  </code></pre>