There are two forms of String.split() methods.
- split(String regex) Splits this string around matches of the given regular expression.
- split(String regex, int limit) - Splits this string around matches of the given regular expression.
This is a complete example to demonstrate the usage of split() methods.
public class SplitExample {
public static void main(String[] args) {
String str = "java,guides.net";
String[] strArray = str.split(",");
for (int i = 0;
i <
strArray.length;
i++) {
System.out.println(strArray[i]);
}
strArray = str.split(",", 0);
for (int i = 0;
i <
strArray.length;
i++) {
System.out.println(strArray[i]);
}
}
}
Output:
java guides.net java guides.net
Reference
Free Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course