The split() method is a Java method that splits a string into substrings based on a specified delimiter. Specify delimiter: Use a regular expression to specify the character or string pattern to split. Call the split() method: Call the split() method on the string you want to split, passing the regular expression as argument. Get split results: The method call returns a String array containing the split substrings.
Usage of split() method in Java
What is the split() method?
The split() method is a Java method used to split a string into substrings based on a specified delimiter.
Syntax:
<code class="java">public String[] split(String regex)</code>
Parameters:
Return value:
How to use split() method:
Example:
<code class="java">String str = "我,爱,Java"; String[] parts = str.split(","); // 输出拆分后的子字符串 for (String part : parts) { System.out.println(part); }</code>
Output:
<code>我 爱 Java</code>
Notes:
The above is the detailed content of How to use split in java. For more information, please follow other related articles on the PHP Chinese website!