URLify a given String - replace spaces with %20
Review
Welcome to Code Review. There are some suggestions as follows.
Consider to use replaceAll
The operation you performed is what String.replaceAll do, you can use replaceAll directly instead of String.toCharArray(), whitespace comparison, and sb.append things.
Create a method URLify
In order to improve usability, it is better to create a method URLify to perform this specific operation.
Summary
Combine all the things:
public class URLify {
    
    public static String URLify(String input){
        return input.stripTrailing().replaceAll(&quot; &quot;,&quot;%20&quot;);
    }
    
    public static void main(String[] args) {
        String str = &quot;Mr John Smith  &quot;;
        System.out.println(URLify(str));
    }
}