Java中String的spilt
2014-05-08 17:04
645 查看
java 中String 的spilt方法是用于按照分割符进行分隔
1、简介
split
public String[] split(String regex)
Splits this string around matches of the given
regular expression.
This method works as if by invoking the two-argument
splitmethod with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.
The string "boo:and:foo", for example, yields the following results with these expressions:
分割符 分割后的字符串
":" “boo” ,“and”,"foo"
2、扩展
当我们随机的输入一段程序时
String ip="192.163.234.345";
String[] str=ip.split(".");
System.out.println(str[2]);
我们认为会输出“345”,当是好奇怪的是:
数组月界,显然数组没有分到4个,断点调试的事后发现,还是原来的字符串,难道spilt方法无效,
于是换一个字符串
String ip="192.163.234.345";
ip = ip.replace(".","a");
String[] str=ip.split("a");
System.out.println(str[2]);
相关文章推荐
- 自己实现Java_String里面的spilt方法,不能借助于string的任何的方法,类
- java String spilt 问题
- Java中截取String中的多个空格成数组
- Java String StringBuffer的区别(性能)
- JAVA中int、String的类型转换
- Java中String、StringBuffer和StringBuilder的区别
- Java中字符串String总结
- JAVA中的String和StringBuffer
- Java中String转MD5
- Java堆、栈和常量池以及相关String的详细讲解(经典中的经典)
- Java面试题——关于String创建几个对象问题
- mybatis报错 There is no getter for property named 'xx' in 'class java.lang.String
- JAVA中int、String的类型转换
- Java堆、栈和常量池以及相关String的详细讲解(经典中的经典)
- Java基础之String与StringBuffer
- java后台的string.valueOf(null)
- java StringBuilder的用法
- java.sql.Date java.util.Date String 之间的转换
- java中的BigDecimal和String的相互转换
- 【java】String的基本操作