I got stuck while converting Array of String to Array of Date
{
String[] departureDate=request.getParameterValues("departureDate");
}
How do I convert the above Strings to Date[] ?
I got stuck while converting Array of String to Array of Date
{
String[] departureDate=request.getParameterValues("departureDate");
}
How do I convert the above Strings to Date[] ?
First of all the sentence:
request.getParameterValues("departureDate");
belongs to ServletRequest.
when you use that code you will get an array of String from your input with name departureDate so if you had something like this for example:
<input type="checkbox" name="departureDate" value="26">day
<input type="checkbox" name="departureDate" value="04">month
<input type="checkbox" name="departureDate" value="1988">year
You will get the array with the values 26,04,1988.
as you can see that is a date, right?
Now everyone want to know what values do you have? so we can help you because you cannot transform a String[] to a Date[].
Solved the problem.
String[] departureDate=request.getParameterValues("departureDate");
List<Date> date=(List<Date>) new Date();
for(String dateToConvert : departureDate) {
try {
Date convertedDate= formatter.parse(dateToConvert);
date.add(convertedDate);
}
catch (ParseException e) {
e.printStackTrace();
}
}