title: Word frequency counter, list not working correctly
body: <p>I have some code that computes word frequencies in a given ArrayList of words. I have a frequency class which essentially stores the word and its respective frequency. Here is my code:</p>
  
  <pre><code>public static List&lt;Frequency&gt; computeWordFrequencies(List&lt;String&gt; words) {
          List&lt;String&gt; wordsList = words; 
          String[] wordsArray = wordsList.toArray(new String[0]);
          Arrays.sort(wordsArray);
          Set&lt;String&gt; noDuplicates = new LinkedHashSet&lt;&gt;(Arrays.asList(wordsArray));
          List&lt;Frequency&gt; frequencies = new ArrayList&lt;&gt;();
          for (String word : noDuplicates) {
              int wordFrequency = Collections.frequency(words, word);
              Frequency newFrequency = new Frequency(word, wordFrequency);
              System.out.println(newFrequency.toString());
              frequencies.add(newFrequency);
          }
          for (Frequency f : frequencies) {
              System.out.println(f.getText()+"               "+f.getFrequency());
          }
          return frequencies; 
      }
  </code></pre>
  
  <p>For reference, Frequency class:</p>
  
  <pre><code>public class Frequency {
  
      private final String word;
      private static int frequency;
  
      public Frequency(String word) {
          this.word = word;
          frequency = 0;
      }
  
      public Frequency(String word, int newfrequency) {
          this.word = word;
          this.frequency = newfrequency;
      }
  
      public String getText() {
          return word;
      }
  
      public int getFrequency() {
          return frequency;
      }
  
      public static void setFrequency(int newFrequency) {
          frequency = newFrequency;
      }
  
      public void incrementFrequency() {
          frequency++;
      }
  
      @Override
      public String toString() {
          return word + ":" + frequency;
      }
  
  }
  </code></pre>
  
  <p>I inserted print statements in my code and this is some of the output:</p>
  
  <blockquote>
    <p>wrapping:1 yard:3 yarn:2 year:2 yet:1 yukon:1 zero:2 abandoned<br>
    2 accordion               2 acequia               2 across<br>
    2 added               2</p>
  </blockquote>
  
  <p>So when the frequencies are created, they have the right frequency, but somehow they later all get changed to 2. What's even more weird is that if I change the second print statement to f.toString(), even the first print statement shows only 2 for the frequencies like this: </p>
  
  <blockquote>
    <p>rising:2 river:2 riveredge:2 riversound:2 road:2 roadrunners:2
    roadside:2 roast:2</p>
  </blockquote>
  
  <p>Can anyone tell me why all of the frequencies get set to 2, or where the problem is?</p>