M
Michael Powe
I have an ArrayList initialized thus:
ArrayList<Date> entryDate = new ArrayList<Date>();
And used in this method:
Date [] sortEntryKeys(ArrayList entryDate){
Date [] sortedEntryDates = null;
Collections.sort(entryDate);
sortedEntryDates = (Date []) entryDate.toArray();
return sortedEntryDates;
The cast to sortedEntryDates throws a ClassCastException when the
method is invoked on an ArrayList of Date objects.
Why? I have another, clunky way of getting the dates into the array,
using System.arraycopy(), but I'd like to know why this way does not
work.
Thanks.
mp
ArrayList<Date> entryDate = new ArrayList<Date>();
And used in this method:
Date [] sortEntryKeys(ArrayList entryDate){
Date [] sortedEntryDates = null;
Collections.sort(entryDate);
sortedEntryDates = (Date []) entryDate.toArray();
return sortedEntryDates;
The cast to sortedEntryDates throws a ClassCastException when the
method is invoked on an ArrayList of Date objects.
Why? I have another, clunky way of getting the dates into the array,
using System.arraycopy(), but I'd like to know why this way does not
work.
Thanks.
mp