URLify a given string ( Replace spaces is % 20 ) | Java implementation of above approach ; Instantiate the string ; Trim the given string ; Replace All space ( unicode is \\ s ) to % 20 ; Display the result
class GFG { public static void main ( String [ ] args ) { String str = " Mr ▁ John ▁ Smith ▁ " ; str = str . trim ( ) ; str = str . replaceAll ( " \\ s " , " % 20" ) ; System . out . println ( str ) ; } }