String compareTo方法

代码:

    public static void main(String[] args) throws Exception
    {        
        // newEffectiveDate.compareTo(oldExpireDate) > 0
        String newEffectiveDate = "2009-04-07";
        String oldExpireDate = "2009-04-07";
        
        if (newEffectiveDate.compareTo(oldExpireDate) > 0)
        {
            System.out.println(" 1 ");
        }
        else if(newEffectiveDate.compareTo(oldExpireDate) == 0)
        {
            System.out.println(" 2 ");
        }else{
            System.out.println(" 3 ");
        }   
    }

结果: 2

 

 

 

你可能感兴趣的:(compareTo)