博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
字符串的分割方法
阅读量:2162 次
发布时间:2019-05-01

本文共 928 字,大约阅读时间需要 3 分钟。

package cn.learn.day08.demo02;/*分割字符串的方法:public String[] split(String regex):按照参数的规则,将字符串切分成为若干部分。注意事项:split方法的参数其实是一个“正则表达式”,今后学习。今天要注意:如果按照英文句点“.”进行切分,必须写"\\."(两个反斜杠) */public class Demo05StringSplit {    public static void main(String[] args) {        String str1 = "aaa,bbb,ccc";        String[] array1 = str1.split(",");        for (int i = 0; i < array1.length; i++) {            System.out.println(array1[i]);        }        System.out.println("===============");        String str2 = "aaa bbb ccc";        String[] array2 = str2.split(" ");        for (int i = 0; i < array2.length; i++) {            System.out.println(array2[i]);        }        System.out.println("===============");        String str3 = "XXX.YYY.ZZZ";        String[] array3 = str3.split("\\.");        System.out.println(array3.length); // 0        for (int i = 0; i < array3.length; i++) {            System.out.println(array3[i]);        }    }}

 

转载地址:http://qgzzb.baihongyu.com/

你可能感兴趣的文章
【python】re模块常用方法
查看>>
剑指offer 19.二叉树的镜像
查看>>
剑指offer 20.顺时针打印矩阵
查看>>
剑指offer 21.包含min函数的栈
查看>>
剑指offer 23.从上往下打印二叉树
查看>>
剑指offer 25.二叉树中和为某一值的路径
查看>>
剑指offer 60. 不用加减乘除做加法
查看>>
Leetcode C++《热题 Hot 100-13》234.回文链表
查看>>
Leetcode C++《热题 Hot 100-14》283.移动零
查看>>
Leetcode C++《热题 Hot 100-15》437.路径总和III
查看>>
Leetcode C++《热题 Hot 100-17》461.汉明距离
查看>>
Leetcode C++《热题 Hot 100-18》538.把二叉搜索树转换为累加树
查看>>
Leetcode C++《热题 Hot 100-19》543.二叉树的直径
查看>>
Leetcode C++《热题 Hot 100-21》581.最短无序连续子数组
查看>>
Leetcode C++《热题 Hot 100-22》2.两数相加
查看>>
Leetcode C++《热题 Hot 100-23》3.无重复字符的最长子串
查看>>
Leetcode C++《热题 Hot 100-24》5.最长回文子串
查看>>
Leetcode C++《热题 Hot 100-26》15.三数之和
查看>>
Leetcode C++《热题 Hot 100-28》19.删除链表的倒数第N个节点
查看>>
Leetcode C++《热题 Hot 100-29》22.括号生成
查看>>