?// 測試字符串 ?String source = "012345678a012345678b012345678c012345678d012345678e012345678f01234"; ?// 規定 長度 ?int needLength = 10; ?// 優化的結果集。 ?// 也可以直接 List<String> resultList = new ArrayList<String>(); ?List<String> resultList = new ArrayList<String>(source.length() ?% needLength + 1); ? ?String subStr; ?int endIndex = 0; ? ?while (source.length() > 0) { ?// 判斷截取的長度 ?endIndex = source.length() > needLength ? needLength : source ?.length(); ?// 獲得街區後的長度 ?subStr = source.substring(0, endIndex); ?// 截取剩余的字符串 ?source = source.substring(endIndex); ?resultList.add(subStr); ?} ?System.out.println(resultList);
上一篇:怎麽註冊tg賬號下一篇:WOWICC打完老二怎麽開H?之後怎麽變回去?