Java Program to Replace Space with Underscore

Java Program to Replace Space with Underscore Article has many meanings. We are going to know this topic clearly through this article. We hope you like this article.

Java Program to Replace Space with Underscore

Java Program to Replace Space with Underscore

public class ReplaceSpace    
{    
    public static void main(String[] args) {    
        String string = "Hello reader! Welcome to Codingdiksha";    
        char ch = '_';    
            
        //Replace space with specific character ch    
        string = string.replace(' ', ch);    
            
        System.out.println("String after replacing spaces with given character: ");    
        System.out.println(string);    
    }    
}   
String after replacing spaces with given character: Hello_reader!_Welcome_to_Codingdiksha

Read Also: Find a String is Palindrome or Not in Java

Final Words

Java Program to Replace Space with Underscore We got to know our topic very clearly. And if you have any doubts about this article you can let us know your doubts via comment.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment