Java 实例 - 字符串分割

Java 教程 · 2019-02-10 07:56:50

以下实例使用了 split(string) 方法通过指定分隔符将字符串分割为数组:

JavaStringSplitEmp.java 文件

public class JavaStringSplitEmp { public static void main(String args[]){ String str = "www-codercto-com"; String[] temp; String delimeter = "-"; // 指定分割字符 temp = str.split(delimeter); // 分割字符串 // 普通 for 循环 for(int i =0; i < temp.length ; i++){ System.out.println(temp[i]); System.out.println(""); } System.out.println("------java for each循环输出的方法-----"); String str1 = "www.codercto.com"; String[] temp1; String delimeter1 = "\\."; // 指定分割字符, . 号需要转义 temp1 = str1.split(delimeter1); // 分割字符串 for(String x : temp1){ System.out.println(x); System.out.println(""); } } }

以上代码实例输出结果为:

www

codercto

com

------java for each循环输出的方法-----
www

codercto

com

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

C++ Concurrency in Action

C++ Concurrency in Action

Anthony Williams / Manning Publications / 2012-2-28 / USD 69.99

HIGHLIGHT C++ Concurrency in Action is the first book to market to show how to take advantage of the new C++ Standard and how to write robust multi-threaded applications in C++. DESCRIPTION With ......一起来看看 《C++ Concurrency in Action》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码

URL 编码/解码
URL 编码/解码

URL 编码/解码