How to enter elemets in a hashmap and check for the existence of a particular key?

How to enter elemets in a hashmap and check for the existence of a particular key?

Hi, 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.

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

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<String,String> hash = new HashMap<String, String>();
                  while((lines = br.readLine())!=null){
                     tokens  = lines.split(",");
                     for(int i=0;i<=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);
              }
    }


}
View Answers









Related Tutorials/Questions & Answers:
How to enter elemets in a hashmap and check for the existence of a particular key?
how to check particular value is avilable in hashmap - Java Beginners
Advertisements
Problem while using a HashMap for writing text ina RTF file. - Framework
How to get Keys and Values from HashMap in Java?
Checking Directory existence on Ftp Server
Checking File existence on Ftp Server
ModuleNotFoundError: No module named 'keyw'
to enter into a particular page only if the username,password and listbox value mtches
Java file exist
HashMap
Hashmap
Mysql Check
HashMap
hashmap
HASHMAP
How to handle enter key in javascript
Hashmap
How to check if a string exits in a string script in Java script?
how to create customise shortcut keys in jsp?
ModuleNotFoundError: No module named 'existence'
ModuleNotFoundError: No module named 'existence'
How to return dictionary keys as a list in Python
How to return dictionary keys as a list in Python
how to sort the elements of hashmap and to print output the key and the value attached to it
Check for any elements exists between the current position and the limit of a buffer.
Check for number of elements exists between the current position and the limit of a buffer.
Check for any elements exists between the current position and the limit of a double type buffer.
Check for number of elements exists between the current position and the limit of a double type buffer.
How to know the Sunrise time of particular date and Location.
Search file on Ftp Server
how to enter matrix data into a table of swings - Java Beginners
JSON to HashMap
how to load a table of data from oracle, to a jsp page using hashmap.
how to check a remote applications validity
how to insert check box
how to check gremlin version
in java, how to store the oputput in tha hard disk in a particular location
How to check a checkbox - Struts
How to check spark version
How to check spark version
How to check if a pid is alive?
How to check a file exists or not in java.
Keys in DBMS
how to write to java program to get the particular data from the website
how to retreive data from database of a particular user after login
How to Send particular error to another page in Servlet from web.xml
how can i close particular frame in swings - Java Beginners
How to read and retrieve jtable row values into jtextfield on clicking at particular row ...
how to send sms from my website to mobile of particular user.
how to show x axis values of timeline chart in jfreechart with particular month.

Ads