public class StringSplit { public static void main(String[] args) { String Str = "1,2,3,4,5"; String[] StrArray = Str.split(","); for (int i = 0; i < StrArray.length; i++) { System.out.println(StrArray[i]); } // 最多分割出3个字符串 int maxSplit = 3; String[] StrArray = Str.split(",", maxSplit); for (int i = 0; i < StrArray.length; i++) { System.out.println(StrArray[i]); } } }