title: Conflicting happens when generating two hashmaps in java
body: <p>I have two text, I make tokenizing and removing stop words then I make lemmatization then I generate an hashmap that contains the lemma and its frequency in the text.</p>
  <p>when I apply above steps on one text everything works fine like below:</p>
  <pre><code>String train = &quot;hamza was studying hamza studied yesterday&quot;;
      String test = &quot;hamza is swimming today&quot;;
  
      sportBag = bagOfWords.Bag(lemmatize.Lemmatize(tokenizeAndRemoveStopWords.RemoveStopWords(train)));
  
      //testBag = bagOfWords.Bag(lemmatize.Lemmatize(tokenizeAndRemoveStopWords.RemoveStopWords(test)));
      System.out.println(&quot;hashmap for train&quot;);
  
      for (String name : sportBag.keySet()) {
          String key = name;
          int value = sportBag.get(name);
          System.out.println(key + &quot; &quot; + value);
      }
  
      System.out.println(&quot;hashmap for test&quot;);
      for (String name : testBag.keySet()) {
          String key = name;
          int value = testBag.get(name);
          System.out.println(key + &quot; &quot; + value);
      }
  </code></pre>
  <p>and the output is as expected</p>
  <pre><code>hashmap for train
  yesterday 1
  study 2
  hamza 2
  </code></pre>
  <p>The problem happens when I generate two hashmaps like below:</p>
  <pre><code>String train = &quot;hamza was studying hamza studied yesterday&quot;;
      String test = &quot;hamza is swimming today&quot;;
  
      sportBag = bagOfWords.Bag(lemmatize.Lemmatize(tokenizeAndRemoveStopWords.RemoveStopWords(train)));
  
      testBag = bagOfWords.Bag(lemmatize.Lemmatize(tokenizeAndRemoveStopWords.RemoveStopWords(test)));
      System.out.println(&quot;hashmap for train&quot;);
  
      for (String name : sportBag.keySet()) {
          String key = name;
          int value = sportBag.get(name);
          System.out.println(key + &quot; &quot; + value);
      }
  
      System.out.println(&quot;hashmap for test&quot;);
      for (String name : testBag.keySet()) {
          String key = name;
          int value = testBag.get(name);
          System.out.println(key + &quot; &quot; + value);
      }
  </code></pre>
  <p>and here the problem happen</p>
  <pre><code>hashmap for train
  yesterday 1
  swimming 1
  study 2
  today 1
  hamza 2
  hashmap for test
  yesterday 1
  swimming 1
  study 2
  today 1
  hamza 2
  </code></pre>
  <p>here is Bag method :</p>
  <pre><code>public Map&lt;String, Integer&gt; words = new HashMap&lt;&gt;();
  
  /**
   * Constructor.
   *
   * @param wordsList
   * @return
   */
  public Map&lt;String, Integer&gt; Bag(List&lt;String&gt; wordsList) {
      for (int i = 0; i &lt; wordsList.size(); i++) {
          int freq = 0;
          for (int j = 0; j &lt; wordsList.size(); j++) {
              if (wordsList.get(j).equals(wordsList.get(i))) {
                  freq++;
              }
          }
          if (!words.containsKey(wordsList.get(i))) {
              words.put(wordsList.get(i), freq);
          }
      }
      return words;
  }
  </code></pre>
  <p>why this happens?</p>