美文网首页java基础学习
java比较两个版本号的大小

java比较两个版本号的大小

作者: 迷糊银儿 | 来源:发表于2020-02-20 20:13 被阅读0次

public class compareVersion {
    public static void main(String[] args){
        String v1="1.0.358";
        String v2="1.0.358_20180820090553";
        String[] v1s=v1.split("[._]");
        String[] v2s=v2.split("[._]");
        int i=0,j=0;
        while (i<v1s.length&&j<v2s.length){
            if(v1s[i].compareTo(v2s[j])>0){
                System.out.println("V1大");
                break;
            }
            else if(v1s[i].compareTo(v2s[j])<0){
                System.out.println("V2大");
                break;
            }
            i++;j++;
        }
        if(i==v1s.length&&v2s.length==j){
            System.out.println("V1=V2");
        }else if(i<v1s.length){
            System.out.println("V1大");
        }else if(j<v2s.length){
            System.out.println("V2大");
        }
    }
}

相关文章

网友评论

    本文标题:java比较两个版本号的大小

    本文链接:https://www.haomeiwen.com/subject/rbdfqhtx.html