- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Split a string in Java
Let’s say the following is our string.
String str = "This,is,it";
We will now see how to split a string using the split() method. Include the delimiter as the parameter.
String[] strSplit = str.split(",");
Add the result in an array and display it.
The following is an example.
Example
public class Demo { public static void main(String[] args) { String str = "This,is,it"; System.out.println("String: "+str); String[] strSplit = str.split(","); System.out.println("Splitting String..."); for (int i = 0; i < strSplit.length; i++) System.out.println(strSplit[i]); } }
Output
String: This,is,it Splitting String... This is it
- Related Articles
- How to split a string in Java?
- Split String with Dot (.) in Java
- Split String with Comma (,) in Java
- Split a string around a particular match in Java
- Java String split() method example.
- Java Program to split a string with dot
- Java program to split and join a string
- Search a string in Matrix Using Split function in Java
- Java StringTokenizer and String Split Example.
- Java Program to split a string using Regular Expression
- How to Split String in Java using Regular Expression?
- How to split a Java String into tokens with StringTokenizer?
- How do we split a string on a fixed character sequence in java?
- How can we split a string by sentence as a delimiter in Java?
- How to split a string in Python

Advertisements