惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - 李小鱼

日语学习网站 大连的夜 郁闷的每一天!!!! (转)带进度条的文件上传(java+ajax,附源码) .net关于给数据库传参 j2ee视频下载地址 java学习网站 (原)关于存储过程事务的写法 (转)判断浏览器的js代码 (转)一段操作Select的JS代码 命令行下的电影 一些功能实现事例 (转)关于乱码问题 关于google查询时 输入框下边显示结果的效果 (转)老紫竹的几句话 (转)Tomcat是如何配置的 (转)Tomcat是如何配置的 (转)关于数据库连接池的形象比喻
(转)java关于split分割字符串,空的字符串不能得到的问题
李小鱼 · 2008-07-10 · via 博客园 - 李小鱼

class T {   
  
public static void main(String args[]) {   
    String num[] 
= new String[11];   
    String sLine 
= "101494|360103660318444|2008/06/17|周润英|1292.0|3085.76|2778.28|912.91|106.0|||";   
    num 
= sLine.split("\\|");   
    
int row = 1;   
    
for (String s : num) {   
      System.out.println(row
+++"="+s);   
    }   
  }   

最有有三个|||,运行结果为
1=101494
2=360103660318444
3=2008/06/17
4=周润英
5=1292.0
6=3085.76
7=2778.28
8=912.91
9=106.0

查看API,有一个

public String[] split(String regex, int limit); 

limit 参数控制应用模式的次数,从而影响结果数组的长度。

如果限制 n 大于零,那么模式至多应用 n> - 1 次,数组的长度不大于 n,并且数组的最后条目将包含除最后的匹配定界符之外的所有输入。

如果 n 非正,那么将应用模式的次数不受限制,并且数组可以为任意长度。

如果 n 为零,那么应用模式的次数不受限制,数组可以为任意长度,

并且将丢弃尾部空字符串。 

修改代码为

class T {   
  
public static void main(String args[]) {   
    String num[] 
= new String[11];   
    String sLine 
= "101494|360103660318444|2008/06/17|周润英|1292.0|3085.76|2778.28|912.91|106.0|||";   
    num 
= sLine.split("\\|",-1); // 这里使用-1作为参数   
    int row = 1;   
    
for (String s : num) {   
      System.out.println(row
+++"="+s);   
    }   
  }   
}  

运行结果为
1=101494
2=360103660318444
3=2008/06/17
4=周润英
5=1292.0
6=3085.76
7=2778.28
8=912.91
9=106.0
10=
11=
12=

结果正常