天天看點

Java中字元串的截取

indexOf()的意思:查找一個字元串中,第一次出現指定字元串的位置。

stringObject.indexOf( value, index );

參數:

value:必需,規定需檢索的字元串值。可選的整數參數。

index:規定在字元串中開始檢索的位置。它的合法取值是 0 到 stringObject.length - 1。如省略該參數,則将從字元串的首字元開始檢索。

測試類:

String path = "_1_389339980_581029995";
        String substring = path.substring(path.indexOf("_")+1);
        System.out.println("列印==="+substring);//列印===1_389339980_581029995

        String[] strings = substring.split("_");
        System.out.println("列印+++"+strings.length);//列印+++3

        List<String> list = Arrays.asList(strings);
        System.out.println("列印==="+list);//列印===[1, 389339980, 581029995]