How to Split a String Only on the First Occurrence of Delimiter ?

Gain Java Knowledge
1 min readMay 10, 2022

In this tutorial we learn how to split based on delimiter within limit.

We know we can split a string over some delimiter in Java.

Suppose we run split() on a string.

String str = “This is a java program”;
str.split(“ “);
This will yield a string array that looks something like this:

[“This”, “is”, “a”, “java” “program”]

Gain Java Knowledge

The Java programming language is one of the most popular languages today. Stay up to date with news, certifications, free learning resources and much more.