The parse method does not try to match the entire input string. That is, the prefix 01-01-2010
matches, and that's enough.
From DateFormat.parse
:
Parses text from the beginning of the given string to produce a date. The method may not use the entire text of the given string.
If you need to figure out if it was a "complete match", you could try the following:
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
String strDate = "01-01-2010mwwwwwwwwwwwwwww";
ParsePosition pp = new ParsePosition(0);
Date date = df.parse(strDate, pp);
System.out.println("Complete match: " + (pp.getIndex() == strDate.length()));
strDate = "01-01-2010";
pp = new ParsePosition(0);
date = df.parse(strDate, pp);
System.out.println("Complete match: " + (pp.getIndex() == strDate.length()));
This prints
Complete match: false
Complete match: true