java中如何使用空格分隔字符串呢?
下文讲述将字符串从空格处拆分的示例分享,如下所示:
拆分字符串的示例
实现思路: 使用split分隔字符串的示例例:
拆分字符串的示例
package com.java265.test;
import java.util.Arrays;
public class TestMain {
public static void main(String[] args) {
String text = "this is my website!";
String[] items = text.split("\\s+");
System.out.println("Length = " + items.length);
System.out.println("Items = " + Arrays.toString(items));
}
}
-----运行以上代码,将输出以下信息-----
Length = 4
Items = [this, is, my, website!]
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


