logo

Java String Split() Method


Show

Description

This way has two alternatives and splits this thread around matches of the known normal expression. The method split() splits a String into numerous Strings given the delimiter that separates them. The returned item is an array that surrounds the split Strings. We can also overtake a limit to the number of elements in the returned array.

Syntax

Here is the syntax of this method:

public String[] split(String regex)

Parameters

Here is the detail of parameters −

  • regex − the delimiting regular expression

Return Value

  • It returns the array of strings computed by splitting this string around matches of the given regular expression.

Example

import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str = new String("Welcome-to-intellinuts.com");
      System.out.println("Return Value :" );      
      
      for (String retval: Str.split("-")) {
         System.out.println(retval);
      }
   }
}

This will produce the following result:

Output

Return Value :
Welcome
to
intellinuts.com

Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.