Home >>Java Programs >Java Program to replace the spaces of a string with a specific character
In this example, we will create a java program to replace all the spaces present in the string with a specific character.
public class Main
{
public static void main(String[] args)
{
String string = "Hello Everyone.. I am Here..";
char ch = '-';
string = string.replace(' ', ch);
System.out.println("String after replacing spaces with given character: ");
System.out.println(string);
}
}