
Hi
i want to date and day in hashmap , 1 want to display according to day with date, how to write aprograme for it.

Here is a HashMap example where we have stored the date and its corresponding day of week.
import java.util.*;
import java.text.*;
class HashMapExample
{
public static void main(String[] args) throws Exception
{
Map<Date, String> m = new HashMap<Date, String>();
DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date d1=dateFormat.parse("5-05-2012");
Date d2=dateFormat.parse("10-06-2012");
Date d3=dateFormat.parse("15-05-2012");
Date d4=dateFormat.parse("20-06-2012");
SimpleDateFormat formatter = new SimpleDateFormat("EEEE");
String day1=formatter.format(d1);
String day2=formatter.format(d2);
String day3=formatter.format(d3);
String day4=formatter.format(d4);
m.put(d1,day1);
m.put(d2,day2);
m.put(d3,day3);
m.put(d4,day4);
Set set = m.entrySet();
Iterator i = set.iterator();
while(i.hasNext()) {
Map.Entry me = (Map.Entry)i.next();
System.out.println(me.getKey() + ": \t "+me.getValue());
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.