CKHypers
Social Media Strategist
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
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:
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
Download
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.
- elements =
str.split
(
","
)
;
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.
- for
(
int
x =
0
;
x <
elements.length
;
x++
)
{
- System
.out
.println
(
elements[
x]
)
;
- }
Output:

Here's the full code of this tutorial:
- public
class
splitString {
- public
static
void
main(
String
[
]
args)
{
- String
str =
"monday,tuesday,wednesday,thursday,friday,saturday,sunday"
;
- String
[
]
elements;
- elements =
str.split
(
","
)
;
- for
(
int
x =
0
;
x <
elements.length
;
x++
)
{
- System
.out
.println
(
elements[
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
Download
You must upgrade your account or reply in the thread to view hidden text.