转:

java 分隔函数split("",-1)的用途

2017年12月14日 11:37:58 jaryle 阅读数:8517
 

1.如果字符串最后一位有值,则没有区别,

2.若干最后n位都是切割符,split(" ")不会继续切分,split(" ", -1)会继续切分

  1. String line = "a b c ";
  2. String [] tmp = line.split(" ");
  3. System.out.println(tmp.length+"------");
  4. for(int i=0;i<tmp.length;i++){
  5. System.out.println(i+"="+tmp[i]);
  6. }
  7.  
  8. String [] items = line.split(" ",-1);
  9. System.out.println(items.length+"========");
  10. for(int i=0;i<items.length;i++){
  11. System.out.println(i+"="+items[i]);
  12. }

结果:

4------
0=a
1=b
2=
3=c
13========
0=a
1=b
2=
3=c
4=
5=
6=
7=
8=
9=
10=
11=
12=

  1. [java] view plain copy
  2. String line = "a b c d";
  3. String [] tmp = line.split(" ");
  4. System.out.println(tmp.length+"------");
  5. for(int i=0;i<tmp.length;i++){
  6. System.out.println(i+"="+tmp[i]);
  7. }
  8.  
  9. String [] items = line.split(" ",-1);
  10. System.out.println(items.length+"========");
  11. for(int i=0;i<items.length;i++){
  12. System.out.println(i+"="+items[i]);
  13. }

结果:

13------
0=a
1=b
2=
3=c
4=
5=
6=
7=
8=
9=
10=
11=
12=d
13========
0=a
1=b
2=
3=c
4=
5=
6=
7=
8=
9=
10=
11=
12=d

java 分隔函数split("",-1)的用途的更多相关文章

  1. Oracle字符分隔函数(split)

    为了让 PL/SQL 函数返回数据的多个行,必须通过返回一个 REF CURSOR 或一个数据集合来完成.REF CURSOR 的这种情况局限于可以从查询中选择的数据,而整个集合在可以返回前,必须进行 ...

  2. java分割函数split的用法(二)

    package com.b; public class Sysetm { public static void main(String[] args) { String a=new String(&q ...

  3. SQL自定义函数split分隔字符串

    SQL自定义函数split分隔字符串 一.F_Split:分割字符串拆分为数据表 Create FUNCTION [dbo].[F_Split] ( @SplitString nvarchar(max ...

  4. Java中的split函数的用法

    Java中的 split  函数是用于按指定字符(串)或正则去分割某个字符串,结果以字符串数组形式返回: 例如: String str="1234@abc"; String[] a ...

  5. 字符串的分隔方法 split()

    java中的split()的方法 string.split([separator,[limit]]) 参数 string (必选),要被分解的 String 对象或文字.该对象不会被 split 方法 ...

  6. C++常见问题: 字符串分割函数 split

    C++标准库里面没有字符分割函数split ,这可太不方便了,我已经遇到>3次如何对字符串快速分割这个问题了.列几个常用方法以备不时之需. 方法一: 利用STL自己实现split 函数(常用,简 ...

  7. (转)C++常见问题: 字符串分割函数 split

    http://www.cnblogs.com/dfcao/p/cpp-FAQ-split.html C++标准库里面没有字符分割函数split ,这可太不方便了,我已经遇到>3次如何对字符串快速 ...

  8. SQL脚本整理系列一 分隔函数

    原来效果: fName Scroe 王某某 ,, 李某某 , 王某某 李某某 李某某 ,, 王某某 执行后效果: name score 李某某 李某某 李某某 王某某 王某某 王某某 王某某 王某某 ...

  9. hive函数 -- split 字符串分割函数

    hive字符串分割函数 split(str, regex) - Splits str around occurances that match regexTime taken: 0.769 secon ...

随机推荐

  1. python之路--MySQL数据库初识

    一 . MySQL安装 # 下载MySQL地址 https://dev.mysql.com/downloads # 要选稳定的,不要选最新的,稳定的就是半年以上没有出现过bug 现在5.6.43为绝大 ...

  2. saltstack一

    Saltstack概述 Salt一种全新的基础设施管理方式,部署轻松,在几分钟内可运行起来,扩展性好,很容易管理上万台服务器,速度够快,服务器之间秒级通讯. salt底层采用动态的连接总线, 使其可以 ...

  3. 老男孩python学习自修第十八天【面向对象】

    1.类与对象(构造方法与实例化) #!/usr/bin/env python # _*_ coding:UTF-8 _*_ class Province: def __init__(self, nam ...

  4. timestamp 与 nonce 防止重放攻击

    重放攻击是计算机世界黑客常用的攻击方式之一,所谓重放攻击就是攻击者发送一个目的主机已接收过的包,来达到欺骗系统的目的,主要用于身份认证过程. 首先要明确一个事情,重放攻击是二次请求,黑客通过抓包获取到 ...

  5. DELPHI中MDI子窗口的关闭 和打开

    Delphi中MDI子窗口的关闭方式默认为缩小而不是关闭,所以当你单击子窗口右上角的关闭按钮时会发觉该子窗口只是最小化,而不是你预期的那样被关闭.解决办法是在子窗口的OnClose事件处理过程中加入如 ...

  6. Microsoft Azure Tutorial: Build your first movie inventory web app with just a few lines of code

    Editor’s Note: The following is a guest post from Mustafa Mahmutović, a Microsoft Student Partner wh ...

  7. python时间模块datetime

    datetime模块 datetime在python中比较常用,主要用来处理时间日期,使用前先倒入datetime模块.下面总结下本人想到的几个常用功能. 1.当前时间(日期.小时.字符串时....) ...

  8. ElasticSearch查询 第四篇:匹配查询(Match)

    <ElasticSearch查询>目录导航: ElasticSearch查询 第一篇:搜索API ElasticSearch查询 第二篇:文档更新 ElasticSearch查询 第三篇: ...

  9. 利用kali破解wifi密码

    准备工具 1.笔记本 2.USB无线上网卡(必备) 3.kali系统 4.密码字典 第一种方法 暴力破解法 何为暴力破解呢,其实就是一个一个密码去试,直到正确的密码. 现在的wifi一般加密都是: 1 ...

  10. BZOJ4475[Jsoi2015]子集选取——递推(结论题)

    题目描述 输入 输入包含一行两个整数N和K,1<=N,K<=10^9 输出 一行一个整数,表示不同方案数目模1,000,000,007的值. 样例输入 2 2 样例输出 16   可以发现 ...