- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
The split() method in Java is used to divide a string into an array of substrings based on a given regular expression (regex). It’s commonly used for parsing and processing text data efficiently.
Example: Splitting by space
public class Main {public static void main(String[] args) {String text = "Java is fun";String[] words = text.split(" ");for (String word : words) {System.out.println(word);}}}Copied!✕CopyOutput:
JavaisfunCopied!✕CopyBasic Syntax
public String[] split(String regex)public String[] split(String regex, int limit)Copied!✕Copyregex – The delimiter pattern (can be a string or regex).
limit – Controls the number of resulting substrings.
Using split() without limit Splits at every match of the regex.
String s = "a::b::c::d";String[] parts = s.split("::");System.out.println(Arrays.toString(parts));// Output: [a, b, c, d]Copied!✕CopyUsing split() with limit
limit > 0 → Splits at most limit - 1 times.
limit = 0 → Splits fully, removes trailing empty strings.
limit < 0 → Splits fully, keeps trailing empty strings.
Java String split () Method - W3Schools
The split() method splits a string into an array of substrings using a regular expression as the separator. If a limit is specified, the returned array will not be longer than the limit.
See results only from w3schools.comJava String Methods
Well organized and easy to understand Web building tutorials with lots of examples of …
W3Schools Tryit Editor
The W3Schools online code editor allows you to edit code and view the result in …
Java For Loop
Java For Loop When you know exactly how many times you want to loop through a …
Final
Definition and Usage The final keyword is a non-access modifier used for classes, …
Throw
The throw statement is used together with an exception type. There are many …
Try It Yourself
The W3Schools online code editor allows you to edit code and view the result in …
Java RegEx
Java does not have a built-in Regular Expression class, but we can import the …
Python String Split
Definition and Usage The split() method splits a string into a list. You can specify …
Certificate
Already know HTML? Earn a W3Schools certificate recognized by employers. Add …
Abstract
Definition and Usage The abstract keyword is a non-access modifier, used for …
Java String split () Method - GeeksforGeeks
Dec 20, 2025 · split () method in Java is used to divide a string into an array of substrings based on a specified delimiter or regular expression. The result of the …
Java String.split () - Baeldung
Mar 13, 2025 · In this article, we explored the String.split () method, which allows us to divide strings into smaller substrings based on specified delimiters. We learned how to use this method with regular …
Searches you might like
Java split string to array - Stack Overflow
Jan 19, 2013 · This method works as if by invoking the two-argument split (java.lang.String,int) method with the given expression and a limit argument of zero. Trailing empty strings are therefore not …
Java String split () - Programiz
The Java String split () method divides the string at the specified separator and returns an array of substrings. In this tutorial, you will learn about the Java split () method with the help of examples.
Mastering Java String `.split()` Method - javaspring.net
Mar 27, 2026 · The split() method in the String class provides a convenient way to split a string into an array of substrings based on a specified delimiter. This blog post will take you through the …
Convert String to Array in Java Using `split` — javathinking.com
Jan 16, 2026 · In this blog post, we will explore the core concepts, typical usage scenarios, common pitfalls, and best practices related to using the split method for converting strings to arrays in Java.
Java String split() : Splitting by One or Multiple Delimiters
Oct 12, 2023 · Java String split () returns an array after splitting the string using the delimiter or multiple delimiters such as common or whitespace.
Java String split () Method
The String.split() method in Java is used to split a string into an array of substrings based on a specified delimiter. This guide will cover the method's usage, explain how it works, and provide examples to …
String (Java Platform SE 8 ) - Oracle Help Center
Constructs a new String by decoding the specified subarray of bytes using the specified charset.