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

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - 李小鱼

日语学习网站 大连的夜 郁闷的每一天!!!! (转)带进度条的文件上传(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=

结果正常