str.split(String sign) str.split(String sign,int limit)
public static void main(String[] args)
{
String Colors="Red,Black,White,Yellow,Blue";
String[] arr1=Colors.split(","); //不限制元素个数
String[] arr2=Colors.split(",",3); //限制元素个数为3
System.out.println("所有颜色为:");
for(int i=0;i<arr1.length;i++)
{
System.out.println(arr1[i]);
}
System.out.println("前三个颜色为:");
for(int j=0;j<arr2.length;j++)
{
System.out.println(arr2[j]);
}
}
所有颜色为: Red Black White Yellow Blue 前三个颜色为: Red Black White,Yellow,Blue
版权说明:Copyright © 广州松河信息科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州松河信息科技有限公司 版权所有