split()方法字符串拆分
2016-05-14 12:26
267 查看
//目的:
// 定义字符串,使用split()方法对字符串进行拆分
// 定义字符串,使用split()方法对字符串进行拆分
//创建类 public class pre1 { // 主方法 public static void main(String args[]) { // 定义的字符串str String str = new String("abc,def,ghi,gkl"); // 使用split()方法对字符串进行拆分,返回字符串数组 String[] newstr = str.split(","); // 使用for循环遍历字符数组 for (int i = 0; i < newstr.length; i++) { // 输出信息 System.out.println(newstr[i]); } System.out.println("第二次拆分"); // 对字符串进行拆分,并限定拆分字符段数,返回字符数组 String[] newstr2 = str.split("g", 3); // 循环遍历字符数组 for (int j = 0; j < newstr2.length; j++) { // 输出信息 System.out.println(newstr2[j]); } } }
相关文章推荐
- spring通知-BeforeAdvice和AfterReturningAdvice
- Android Development Environment ADT-BUNDLE android-studio SDK ADT Download
- ORA-12154: TNS: 无法解析指定的连接标识符
- 玩转ptrace (一)
- Bullet Physics Engine(物理引擎)中使用约束
- eclipse + pydev 创建django项目
- C++ 传递对象---用值传递对象
- Spring Boot 中使用log4jdbc记录SQL的运行时参数
- 下载Google地图,瓦片数据和经纬坐标的切换
- PhpStorm许可server地址
- Matlab Tricks(七)—— 矩阵列/列的归一化/单位化(normalize)
- 大数据学习线路图
- Android高阶之AS如何打.aar包,并应用
- 自定义Dialog(2)
- jupyter notebook 各种用法记录(陆续更新)
- (3)使用IntelliJ IDEA建立maven项目
- 【中间件】(一):中间件原来和分布式有关系……
- PHP设计模式:观察者模式
- Guido von Rossum - i wrote python
- HDU 1029 Ignatius and the Princess IV