Java Tutorial

Java Control Statements

Object Oriented Programming

Java Built-in Classes

Java File Handling

Java Error & Exceptions

Java Multithreading

Java Synchronization

Java Networking

Java Collections

Java List Interface

Java Queue Interface

Java Map Interface

Java Set Interface

Java Data Structures

Java Collections Algorithms

Java Miscellaneous

Advanced Java

Java APIs & Frameworks

Java Useful Resources

Java - String split() Method



Description

This method has two variants and splits this string around matches of the given regular expression.

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-Tutorialspoint.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
Tutorialspoint.com
java_strings.htm
Advertisements