Split a String in Java
Submitted by donbermoy on Wednesday, December 24, 2014 - 21:51.
This tutorial will teach you how to create a program that will split a string using java.
So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of splitString.java.
2. We will initialize variables in our Main, variable str as a String, and variable elements as a String array.
3. To split the string in variable str, we will use the split method of the str with the elements of the String array.
As you can see, i have choose to have comma "," on the split keyword so that all the commas in the String will be omitted. The split keyword means to omit those characters in the string. Note: You can change the comma keyword into any characters that you want.
4. To display the text that was split, we will declare a for loop because the string now was an array.
Output:
Here's the full code of this tutorial:
- elements = str.split(",");
- for (int x = 0; x < elements.length; x++){
- }

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
Add new comment
- 62 views