How to enter elemets in a hashmap and check for the existence of a particular key?
<p>I am trying to read a csv file and storing its contents in a hash map and checking the existence of a particular key in the hash map.</p>

<p>Here is my code,Please let me know where am i wrong because i m ant able to figure out my mistake</p>

<pre><code>import java.io.*;

import java.text.SimpleDateFormat;

import java.util.*;

public class PoolCsv {

    public static void main(String[] args) {

        try {

            Calendar currentdate = Calendar.getInstance();
            SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
            String presdate = dateformat.format(currentdate.getTime());
            currentdate.add(Calendar.DAY_OF_YEAR, 4);
            String futdate = dateformat.format(currentdate.getTime());
            System.out.println(presdate);
            System.out.println(futdate);
            String poolcsv = "D:\\pool_items.csv";
            BufferedReader br = new BufferedReader(new FileReader(poolcsv));
            String lines = null;
            String[] tokens = null;
            String startdate = null;
            String enddate = null;
            HashMap&lt;String, String&gt; hash = new HashMap&lt;String, String&gt;();
            while ((lines = br.readLine()) != null) {
                tokens = lines.split(",");
                for (int i = 0; i &lt;= tokens.length; i++) {
                    startdate = tokens[5];
                    enddate = tokens[6];
                }

                hash.put(startdate, enddate);

                boolean flag = hash.containsKey(presdate);
                if (flag) {
                    System.out.println("value exists");
                }
            }

        } catch (IOException io) {
            System.out.println(io);
        }
    }
}
</code></pre>
