Program to replace every space in a string with hyphen | Java implementation of the above approach ; Split by space and converting String to list and ; returning the string ; Driver code
import java . util . * ; class GFG { static String printHyphen ( String string ) { string = string . replace ( ' ▁ ' , ' - ' ) ; return string ; } public static void main ( String [ ] args ) { String string = " Text ▁ contains ▁ malayalam ▁ and ▁ level ▁ words " ; System . out . print ( printHyphen ( string ) ) ; } }