title: Sorting two List (String, Integer) in java based on Integer value
body: <p>I am working on a program where i am reading a file and extracting keywords and their count. Later i need to pick up word with topmost frequency and match them with a keyword. </p>
  
  <p>I have stored all the keywords i have found in the file in String list. 
  I wish to sort these on basis of frequency. So if at index 17 i have a word "stack" with value at index 17 in other integer list to be maximum, i wish to take them to position 1. </p>
  
  <p>I can sort these using collections.sort but it does not take care of other list. </p>
  
  <p>Here is my code :</p>
  
  <pre><code>while(m.find()) 
      {
          if(keyword.contains(m.group()))
              {
              keywordcount.set(keyword.indexOf(m.group()),keywordcount.get(keyword.indexOf(m.group()))+1);
              //System.out.println("*"+m.group()+":"+keywordcount.get(keyword.indexOf(m.group())));
              }
          else
              {
              keyword.add(m.group());
              int var=keyword.indexOf(m.group());
              //System.out.println(m.group()+":"+var);
              keywordcount.add(var, 1);
              }
          //System.out.println(keyword.size()+"#"+keywordcount.size());                       
      }
      for(int i=0;i&lt;keyword.size();i++)
      {
          System.out.print(keyword.get(i)+ ":" +keywordcount.get(i)+" ");
      }
  </code></pre>