Java split方法

Stringstr="A,,,,,,,"String[]list=str.split(",");list.length=1;list={"A"};有不有办法分割成这样的?... String str = "A,,,,,,,"
String[] list = str.split(",");
list.length = 1 ;
list = {"A"};
有不有办法分割成这样的?
list = {"A", "", "", "", "", ""};
展开
 我来答
孤独的探戈1573
推荐于2017-10-10 · TA获得超过580个赞
知道小有建树答主
回答量:238
采纳率:0%
帮助的人:156万
展开全部

java中String的split方法有两个,

  1. split(String regex)   根据给定正则表达式的匹配拆分此字符串。例如:将下列字符串以“a”分割,


  2. public String[] split(String regex,
                         int limit)

    参数:regex - 定界正则表达式

    limit - 结果阈值

    例如下:


    其中:limit来限制被分割后数组的元素个数;

百度网友d44faec
2011-05-28 · TA获得超过640个赞
知道小有建树答主
回答量:699
采纳率:0%
帮助的人:186万
展开全部
楼上正解。下面是java文档中关于split(两参数)函数的说明。
public String[] split(String regex, int limit)
Splits this string around matches of the given regular expression.

The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string. The substrings in the array are in the order in which they occur in this string. If the expression does not match any part of the input then the resulting array has just one element, namely this string.

The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n - 1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
syb426
2011-05-28 · 超过14用户采纳过TA的回答
知道答主
回答量:18
采纳率:0%
帮助的人:37.6万
展开全部
import java.util.*;
public class Chartest
{
public static void main(String[] args){
String str = "A,,,,,,,";
String[] list = str.split("");
for(String s:list)
System.out.println(s);
}
}
追问
这个分割的东西都不太对了. 是以空串来分割的了.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
koeiol
2011-05-28 · TA获得超过677个赞
知道小有建树答主
回答量:126
采纳率:0%
帮助的人:173万
展开全部
String[] list = str.split(",", -1);
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式