Replace the spaces of a string with a specific character using Java

Configurare noua (How To)

Situatie

  1. public class ReplaceSpace
  2. {
  3.     public static void main(String[] args) {
  4.         String string = “Once in a blue moon”;
  5.         char ch = ‘-‘;
  6.         //Replace space with specific character ch  
  7.         string = string.replace(‘ ‘, ch);
  8.         System.out.println(“String after replacing spaces with given character: “);
  9.         System.out.println(string);
  10.     }
  11. }

Output:

String after replacing spaces with given character: 
Once-in-a-blue-moon

Solutie

Tip solutie

Permanent

Voteaza

(9 din 20 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?