In order to Split a String in Java, you need to make use of the split(String regex) function provided in java.lang.String class. Let's see an example.
Input String: "This is some text that I want to split by spaces into an Array of Strings."Code Snippet:
package com.code2care.java.tutorials;
public class JavaStringSplitBySpace {
public static void main(String[] args) {
String dataString = "This is some text that I want to split by spaces into an Array of Strings.";
String[] dataStringArr = dataString.split("\\s");
for (String data : dataStringArr) {
System.out.println(data);
}
}
}
Output:
This
is
some
text
that
I
want
to
split
by
spaces
into
an
Array
of
Strings.
Java - Split a String by spaces
More Posts related to Java,
- CRUD operations in Spring Boot + JDBC
- Java Check Leap Year - Programs with Code Examples
- [fix] Java JDBC ConnectException: Connection refused
- How to add hours and minutes to Java Instant
- Java Program: Random Number Generator
- Java: The value of the local variable string is not used
- How to get list of all Java versions installed on macOS
- Java SE JDBC with Prepared Statement Parameterized Select Example
- Java + Spring JDBC Template + Gradle Example
- Convert String to LocalDate in Java
- Remove Trailing zeros BigDecimal Java
- Java 8 Predicate Functional Interface isEqual() Method Example
- How to Hardcode Date in Java with Examples
- Java 8: Predicate negate() default Function Example
- Java: Collect Stream as ArrayList or LinkedList
- The Motivation Behind Generics in Java Programming
- How to Add/Subtract Days to the Current Date in Java
- Error: Can not find the tag library descriptor for
- Setting up JUnit 5 dependency with Maven Example
- Run Java Code Every Second
- How to create a tar.gz file using Java
- [Fix] java: integer number too large compilation error
- Java 8: Find the Max value in a List
- Your JBoss Application Server 7 is running However you have not yet added any users to be able to access the admin console
- Convert Java Array to ArrayList Code Example
More Posts:
- How to create SharePoint List Item programmatically using C#.net - SharePoint
- How to Insert Checkbox in Excel on Mac - Windows
- Fix PowerShell - .ps1 cannot be loaded because running scripts is disabled on this system - Powershell
- Move Copy Migrate SharePoint OneDrive files folders to different site collection location - SharePoint
- SharePoint list excel import error - Title is a required filed and can't be empty - SharePoint
- How to run a Command in Bash Script - Bash
- Mac - How to Install VirtualBox - MacOS
- How to take user input from the console in a Python program - Python