title: Converting a awk 2D array with counts into hashmap in java
body: <p>I found this problem so interesting. I am using an awk 2D array that has a key,value,count of the same. and that is being printed to a file. This file is in the below format</p>
  
  <pre><code>A100|B100|3
  A100|C100|2
  A100|B100|5
  </code></pre>
  
  <p>Now I have a file like this .. My motive is to convert this file into a hash map so that the final output from the hash map is.</p>
  
  <pre><code>A100|B100|8
  A100|C100|2
  </code></pre>
  
  <p>Just an aggregation</p>
  
  <p>The challenge is, this one has 3 dimensions and not two. I did have an another file in the below format which is </p>
  
  <pre><code>D100|4
  H100|5
  D100|6
  </code></pre>
  
  <p>I easily aggregated the above as it is only 2D and I used the below code to do that </p>
  
  <pre><code>String[] fields= strLine.trim().split("\\|");
  if(hashmap.containsKey(fields[0]))
  {
  //Update the value of the key here
  hashmap.put(fields[0],hashmap.get(fields[0]) + Integer.parseInt(fields[1]));
  }
  else
  {
  //Inserting the key to the map
  hashmap.put(fields[0],Integer.parseInt(fields[1]));
  }
  </code></pre>
  
  <p>So this was quite simple for implementation.</p>
  
  <p>But when it comes to 3D I have to have an another check inside.. My idea for this is to maintain a [B100,5(beanObject[5])]</p>
  
  <pre><code>  Map&lt;String,beanClassObject&gt; hashmap=new Map&lt;String,beanClassObject&gt;();
  </code></pre>
  
  <p>secongField hash map which has been used in the code that has a mapping relation between the created ben Object subscript and the key as the second field "For instance it is "</p>
  
  <p>This bean class would have the getter and setter method for the 2nd and 3rd fields of the file. I hope I am clear with this point. So the implementation of this would be </p>
  
  <pre><code>if(hashmap.containsKey(fields[0]))
  {
     **//Have to check whether the the particular key value pair already exists ... I dint find any method for this ... Just a normal iteration is there .. Could you ppl guide me regarding this**
  
      //Update the value of the key here
       secondFieldHashMap.get(fields[1]).COunt= secondFieldHashMap.get(fields[1]).getCOunt+ Integer.parseInt(fields[2]));
     }
     else
      {
       //Inserting the key to the map
       hashmap.put(fields[0],Integer.parseInt(fields[1]));
       secondFieldHashMap.get(fields[1]).COunt=  Integer.parseInt(fields[2]));
      }
  else
  {
  
   // This meands there is no key field
   // Hence insert the key field and also update the count of seconfFieldHashMap as done previously.
   }
  </code></pre>
  
  <p>COuld you ppl please throw some ideas regarding this. Thank you</p>