title: Split the string of text file and store it in HashMap
body: <p>I have a text file which has data as follows:</p>
  
  <pre><code>Surrender~abc~nov@2012
  Surrender~bnc~bhdgvx
  Surrender~nkhjb~bcdjh
  .
  .
  .
  </code></pre>
  
  <p>I want to separate the data row by row and store second and third column values in Hashmap as 2nd -> key and 3rd -> value and check if the value entered by user exist in the Hashmap and return true.</p>
  
  <p>I tried following but getting <code>java.lang.ArrayIndexOutOfBoundsException: 3</code>..Please guide.</p>
  
  <pre><code>HashMap hm = new HashMap();
  FileInputStream fstream = new FileInputStream("Surrender.txt");
  DataInputStream in = new DataInputStream(fstream);
  BufferedReader br = new BufferedReader(new InputStreamReader(in));
  
  String strLine;
  while ((strLine = br.readLine()) != null)   {
      String[] parts = strLine.split("~");
      for (int i = 0; i &lt;= parts.length; i++) {
         if(!parts[i].equalsIgnoreCase("Surrender")){
      String key=parts[i];
      String value=parts[i++];
      if(key!=null &amp;&amp; value!=null)
      hm.put(key,value);
  }
      }
  }
  
  System.out.println("HashMap size..." + hm.size());
  in.close();
  </code></pre>