Raw replacement of space by %20 in Java
We should understand what's happening when we do string-related operations in Java. When we concat strings in java, like

 String result = "";
 for(int i=0; i&lt;100; i++){        
    result += i+","; // bad, because each string + string creates new string 
 }


Strings are immutable, so its bad to += them, instead, StringBuilder is used. 
Here's another way to solve this task:

public class ReplaceSpace {

  private static final String REPLACE_SPACE = "%20";
  private static final String SPACE = " ";

  public static void main(String[] args) {
    String input = "Just    some input     string to perform stuff     !";
    System.out.println(replaceString(input));
  }

  private static String replaceString(String input) {
    StringBuilder sb = new StringBuilder();

    int lastPoint = 0;
    int foundIndex;
    int maxIndex = input.length() - 1;
    while ((foundIndex = input.indexOf(SPACE, lastPoint)) != -1 &amp;&amp; foundIndex &lt;= maxIndex) {
        sb.append(input.substring(lastPoint, foundIndex - 1));
        sb.append(REPLACE_SPACE);

        lastPoint = foundIndex;
    }

    sb.append(input.substring(lastPoint));

    return sb.toString();
    }

}