Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 44e2270

Browse files
Fixing bug in StringBuilder
1 parent 6720197 commit 44e2270

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

‎src/com/deepak/data/structures/Strings/CustomStringBuilder.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public CustomStringBuilder() {
4444
public void append(String input) {
4545
if (input != null) {
4646
char[] charArray = input.toCharArray();
47-
if (overflow(charArray.length)) {
47+
/* Using while loop here because of below use case,
48+
* 1. Initial character buffer initialized with size 10
49+
* 2. Input string came of size 25
50+
* 3. We need to check for overflow 2 times now because size will be increased by 10 only in one time */
51+
while (overflow(charArray.length)) {
4852
ensureCapacity();
4953
}
5054
for (int i = 0; i < charArray.length; i++) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /