当前位置: 首页 > 文档资料 > 学习 Java 编程 >

String[] split(String regex)

优质
小牛编辑
116浏览
2023-12-01

描述 (Description)

此方法有两个变体,并围绕给定正则表达式的匹配拆分此字符串。

语法 (Syntax)

以下是此方法的语法 -

public String[] split(String regex)

参数 (Parameters)

这是参数的细节 -

  • regex - 分隔正则表达式。

返回值 (Return Value)

  • 它返回通过将此字符串拆分为给定正则表达式的匹配而计算的字符串数组。

例子 (Example)

import java.io.*;
public class Test {
   public static void main(String args[]) {
      String Str = new String("Welcome-to-iowiki.com");
      System.out.println("Return Value :" );      
      for (String retval: Str.split("-")) {
         System.out.println(retval);
      }
   }
}

这将产生以下结果 -

输出 (Output)

Return Value :
Welcome
to
iowiki.com