// java 中分割字符串, String sourceStr = "1,2,3,4,5"; String[] sourceStrArray = sourceStr.split(","); for (int i = 0; i < sourceStrArray.length; i++) { Log.e("TAG", "-----中分割字符串-----"+sourceStrArray[i]); } int maxSplit = 3; sourceStrArray = sourceStr.split(",", maxSplit); for (int i = 0; i < sourceStrArray.length; i++) { Log.e("TAG", "-----java中分割字符串-----"+sourceStrArray[i]); } }
输出结果为:
2020-06-17 11:12:55 E/TAG: -----中分割字符串-----1
2020-06-17 11:12:55 E/TAG: -----中分割字符串-----2
2020-06-17 11:12:55. E/TAG: -----中分割字符串-----3
2020-06-17 11:12:55. E/TAG: -----中分割字符串-----4
2020-06-17 11:12:55. E/TAG: -----中分割字符串-----5
2020-06-17 11:12:55. E/TAG: -----java中分割字符串-----1
2020-06-17 11:12:55. E/TAG: -----java中分割字符串-----2
2020-06-17 11:12:55. E/TAG: -----java中分割字符串-----3,4,5