Hey, Welcome to the Practice House. In this post, we will learn how to Remove special Character from a string in java. We will also learn how to join the split String in Java.
In our scenario, we got hyphen in our String So to remove this hyphen we can use the split()
method. If you have any complex special Character please use RegEx. Please visit their official website to learn more about RegEx.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
package com.practicehouse.examplePrograms; import java.util.Arrays; public class SplitAndJoin { public static void main(String[] args) { String accountNumber = "125-0987897-876"; String[] words = accountNumber.split("-"); System.out.println("After Splitted :" + Arrays.toString(words)); accountNumber = String.join("", words); System.out.println("Finally our Account Number: " + accountNumber); } } |
Sample Output:
1 2 3 |
Account Number : 125-0987897-876 After Splitted :[125, 0987897, 876] Finally our Account Number: 1250987897876 |
Thank you so much for reading this post. If you have any questions and comments please comments below.

Java – PHP – Python – Dart – Flutter – MySql – Spring – Hibernate – JavaScript – jQuery – BootStrap 4 – CSS – HTML
I love to explore new technologies. If you like my tutorials please share your thoughts about my work.
Check out my YouTube Channel For Video Tutorials.
To Hire Me Please Contact Me Through Social Media or https:www.amialif.com
If you want to help others by doing donation please Help Them.
You also can connect with me via social media. Thanks
Leave a Reply