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.
用这个函数应该足够了

解决方案 »

  1.   

    要求要写check(object a ,string b)
    {
    如果    a.c1<b <a.d1 返回ture
    如果    a.c2<b <a.d2 返回ture
    如果    a.c3<b <a.d3 返回ture   }
    现在 就是不知道该如何比较a.c1<b <a.d1
      

  2.   

    compareTo
    a.compareTo(b)当a>b时返回1
    a=b时候返回0
    a<b时候返回-1
      

  3.   


    要求要写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;   }
      

  4.   

    楼上的方法不行的 a.compareTo(b) 只能得到a中是否包含有b这样的子串
      

  5.   

    那你试验一下a='200'
    b='20'
    先看看a.compareTo(b)返回什么?
    然后在把a改成'020'
    再看看a.compareTo(b)返回什么?
      

  6.   

    要是YYYYMMDD格式的话直接用>小于号就行了。
      

  7.   

    对拉 不知道可否用Integer.parseInt(a.c1)
      

  8.   

    可以
    如果是YYYYMMDD格式的话。如果是YYYY-MM-DD格式就不行了。
    没必要转
    直接用大小于号就可以比了。
      

  9.   

    String.compareTo(Object)是按位比较的,可以用