如何使用java代码从字符串中提取第一个单词呢?
下文笔者讲述使用java代码从字符串中提取第一个单词的方法分享,如下所示:
实现思路:
使用split方法,即可实现字符串的截取操作
例:
package com.java265.other;
public class Test17 {
/**
* java265.com 示例程序
*/
public static void main(String[] args) {
String mystring = "this is my website!";
String arr[] = mystring.split(" ", 2);
String one = arr[0];
String two = arr[1];
System.out.println("one:" + one);
System.out.println("two:" + two);
}
}
------运行以上代码,将输出以下信息-----
one:this
two:is my website!
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


