StringBuilderUtils { public static void replace(@NonNull StringBuilder stringBuilder, @NonNull String toReplace, @NonNull String replacement) { int index = stringBuilder.indexOf(toReplace); if (index >= 0) { stringBuilder.replace(index, index + toReplace.length(), replacement); } }  static void replace(@NonNull StringBuilder stringBuilder,
                        @NonNull String toReplace,
                        @NonNull String replacement); static void trim(@NonNull StringBuilder stringBuilder); static boolean isEmpty(@NonNull StringBuilder stringBuilder); static boolean startsWith(@NonNull StringBuilder stringBuilder, @NonNull String start); static boolean contains(@NonNull StringBuilder stringBuilder, @NonNull String contains); static boolean equals(@NonNull StringBuilder stringBuilder, @NonNull String equal); @NonNull static StringBuilder substring(@NonNull StringBuilder stringBuilder, int start, int end);  }
@Test public void replace_SingleCharacter() { StringBuilder stringBuilder = new StringBuilder("abbbaacccda"); StringBuilderUtils.replace(stringBuilder, "a", ""); Assert.assertEquals(stringBuilder.toString(), "bbbaacccda"); }
@Test public void replace_MultipleCharacters() { StringBuilder stringBuilder = new StringBuilder("___ab___cd___"); StringBuilderUtils.replace(stringBuilder, "___", "---"); Assert.assertEquals(stringBuilder.toString(), "---ab___cd___"); }