title: Anagrams finding in java
body: <p>I stuck on a problem. I have a String array which is consist of <code>String[]={"eat", "tea", "tan", "ate", "nat", "bat"}</code> Now, I should segregated those word which have same letter on it and make a group. <code>eat,tea,ate</code> they have same letter in each word so this is a group. Group 2 should be <code>tan,nat</code> and Group3 should be <code>bat</code>. So I have to make a list of list to store those groups. </p>
  
  <p><strong>My approach:</strong> </p>
  
  <p>To solve this problem I first find out the ascii values of each letter and then add those ascii values for a word. Like <code>eat</code> find out the ascii values of <code>e,a,t</code> and add them. I take this approach because if the letters are repeated in the words then they must have same ascii sum. After that I group them same Ascii sums and find out which words have those sums then they belongs to same group.</p>
  
  <p><strong>My progress</strong> 
  I find out  ascii sums and put them in a hashmap. But then I could not  group the same values. As I failed to group the ascii values I cannot find out the words.I have no clue how to proceed. </p>
  
  <p>I also follow this posts</p>
  
  <p><a href="https://stackoverflow.com/questions/18834128/c-finding-anagrams-in-words">post1</a>
  <a href="https://stackoverflow.com/questions/47821779/finding-anagram-using-hashmap">post2</a></p>
  
  <p>But there approach and my approach is not same. Also the questions are different from mine. I am discussing here about a different approach which is depend upon ASCII values.</p>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>public List&lt;List&lt;String&gt;&gt; groupAnagrams(String[] strs) {
      ArrayList&lt;Character&gt;indivistr=new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt;dup=new ArrayList&lt;&gt;();
      HashMap&lt;Integer,Integer&gt;mappingvalues=new HashMap&lt;&gt;();
      for(int i=0;i&lt;strs.length;i++){
          int len=strs[i].length();
          int sum=0;
          for(int j=0;j&lt;len;j++){
              indivistr.add(strs[i].charAt(j));
              int ascii=(int)strs[i].charAt(j);
              sum=sum+ascii;
  
          }
          mappingvalues.put(i,sum);
  
      }
  </code></pre>
  
  <p>}</p>
  
  <p><em>One more approach</em>
  I transfer the map keys in a Arraylist and map values in a ArrayList. Something like that,</p>
  
  <p><code>ArrayList&lt;Integer&gt;key_con=new ArrayList&lt;
  (mappingvalues.keySet());
   ArrayList&lt;Integer&gt;val_con=new ArrayList&lt;&gt;(mappingvalues.values());</code></p>
  
  <p>Then using two loops and put the same values into another list. </p>
  
  <pre><code>for(int k=0;k&lt;val_con.size();k++){
          for(int k1=k+1;k1&lt;val_con.size();k1++){
              if(val_con.get(k).equals(val_con.get(k1))){
                  dup.add(val_con.get(k1));
              }
          }
  </code></pre>
  
  <p>Now if I print dup output will be <code>[314, 314, 314, 323]</code> which is partially correct. It should be <code>314,314,314,323,323,311</code></p>