public int compareTo(Object o)
Compares this String to another Object. If the Object is a String, this function behaves like compareTo(String). Otherwise, it throws a ClassCastException (as Strings are comparable only to other Strings). Specified by:
compareTo in interface Comparable
Parameters:
o - the Object to be compared.
Returns:
the value 0 if the argument is a string lexicographically equal to this string; a value less than 0 if the argument is a string lexicographically greater than this string; and a value greater than 0 if the argument is a string lexicographically less than this string.
Throws:
ClassCastException - if the argument is not a String.
用这个函数应该足够了
Compares this String to another Object. If the Object is a String, this function behaves like compareTo(String). Otherwise, it throws a ClassCastException (as Strings are comparable only to other Strings). Specified by:
compareTo in interface Comparable
Parameters:
o - the Object to be compared.
Returns:
the value 0 if the argument is a string lexicographically equal to this string; a value less than 0 if the argument is a string lexicographically greater than this string; and a value greater than 0 if the argument is a string lexicographically less than this string.
Throws:
ClassCastException - if the argument is not a String.
用这个函数应该足够了
{
如果 a.c1<b <a.d1 返回ture
如果 a.c2<b <a.d2 返回ture
如果 a.c3<b <a.d3 返回ture }
现在 就是不知道该如何比较a.c1<b <a.d1
a.compareTo(b)当a>b时返回1
a=b时候返回0
a<b时候返回-1
要求要写check(object a ,string b)
{
if(a.c1.compareTo(b)<0&&a.d1.compareTo(b)>0)
return true;if(a.c2.compareTo(b)<0&&a.d2.compareTo(b)>0)
return true;
if(a.c3.compareTo(b)<0&&a.d3.compareTo(b)>0)
return true;
return false; }
b='20'
先看看a.compareTo(b)返回什么?
然后在把a改成'020'
再看看a.compareTo(b)返回什么?
如果是YYYYMMDD格式的话。如果是YYYY-MM-DD格式就不行了。
没必要转
直接用大小于号就可以比了。