Source Code:
public class ReplaceSpaces {
public static void main(String[] args) {
String s = “java is easy”;
String res = s.replace(‘ ‘, ‘-‘);
System.out.println(res);
}
}
Output:
public class ReplaceSpaces {
public static void main(String[] args) {
String s = “java is easy”;
String res = s.replace(‘ ‘, ‘-‘);
System.out.println(res);
}
}