stringbuilder Questions

1

Solved

By amortized analysis, we know that N insertions with StringBuilder#append method take O(N) time. But here is where I get lost. Consider this where inputString is an input string from a user. for ...
Stubbs asked 27/6, 2019 at 22:19

6

I have the following code: StringBuilder sb = new StringBuilder(); sb.Append("Ola"); sb.Append("Jola"); sb.Append("Zosia"); Can I iterate over StringBuilder object using for, or foreach? Can I ...
Basilica asked 1/7, 2015 at 10:42

1

Solved

Knowing that String implements CharSequence interface, so why does StringBuilder have a constructor for CharSequence and another one for String? No indication in the javadoc ! public final class S...
Overhear asked 13/5, 2019 at 6:12

1

I try to understand how reduce() method works exactly with parallel streams and I don't understand why the following code do not return the concatenation of these strings. This is the code: publ...
Ahearn asked 7/5, 2019 at 13:13

3

Solved

following this and this documentation I would use the QStringBuilder in a for loop. The code where I should apply it is QStringList words; QString testString; for (auto it = words.constBegin(); i...
Budget asked 29/8, 2012 at 21:43

4

Solved

Here's some simple Java code: String s = new StringBuilder().append("a").append("b").append("c").toString(); I compile it with JRE 1.6, and I observe the following in the decompiled class file: ...
Scourings asked 25/9, 2014 at 21:43

4

Solved

Groovy supports a literal syntax for creating a StringBuilder/StringBuffer instead of the usual def sb = new StringBuilder() However, I can't seem to remember (or find on Google) the correct syn...
Gad asked 25/11, 2009 at 14:56

8

Solved

How do you append a new line(\n\r) character in StringBuilder?
Calbert asked 11/4, 2010 at 16:34

9

Solved

What is the most efficient/elegant way to dump a StringBuilder to a text file? You can do: outputStream.write(stringBuilder.toString().getBytes()); But is this efficient for a very long file? ...
Rhodia asked 4/11, 2009 at 22:42

3

Solved

I'm building a stress-testing client that hammers servers and analyzes responses using as many threads as the client can muster. I'm constantly finding myself throttled by garbage collection (and/o...
Morelos asked 18/7, 2012 at 1:32

5

Solved

I want to concatenate or append special character as colon : after an every 2 character in String. For Example: Original String are as follow: String abc =AABBCCDDEEFF; After concatenate or a...
Orient asked 24/1, 2019 at 11:27

1

Solved

As can be seen here, one of String.Join's overloads works with raw pointers and uses something called UnSafeCharBuffer. Why is this? Is it a performance optimization?
Fallible asked 17/1, 2019 at 21:33

5

Solved

I have to use StringBuilder instead of a List of strings because of being stuck with .NET 1.1 for this project. I want to write a series of debug messages I've written to a file to study at my le...
Personalize asked 15/3, 2013 at 23:32

2

Solved

example code: StringBuffer sb = new StringBuffer("hi"); sb = null; Question: will the literal string "hi" somehow stay in memory, even after the StringBuffer has been garbage collected? O...
Hailstorm asked 20/12, 2018 at 21:28

1

Solved

Introduction I have an app and want to force the user to update it, if a new version is at the google play market. This is working fine with the following code but is not very stable. I am doing i...
Pledgee asked 13/11, 2018 at 9:45

1

Solved

What's the most efficient way to concatenate strings, if I already only have ReadOnlySpan slices? Simplified example: public class Program { public string ConcatSpans(string longstring) { var s...
Guttering asked 6/11, 2018 at 21:33

5

Solved

In vb.net (or C#) I can't figure out how to compare a stringbuilder to a string. I have searched quite a bit and can't find the answer. I had to write my own routine. Isn't there a better way? Thi...
Siglos asked 26/8, 2014 at 13:40

8

Solved

I have an ArrayList with some Strings. I want to store that list of numbers from the ArrayList in a single string separated by a comma like the following. String s = "350000000000050287,3921564868...
Wordsmith asked 8/10, 2015 at 17:58

5

Solved

I have a small problem: I have a List of fields, with 3 Values. I want to build my String with these three Values, delimited by a "TAB".. Code: StringBuilder stringBuilder = new StringBuilder();...
Incurve asked 8/2, 2012 at 10:44

8

Solved

I am building a validation routine that validates contents and then gives warning (for failures) in form of StringBuilder. Say in below code I am checking lower bound for values paramX and paramY. ...
Athenian asked 6/11, 2013 at 13:31

5

Solved

I recently encountered with a Java 8 class StringJoiner which adds the String using the delimiters and adds prefix and suffix to it, but I can't understand the need of this class as it also uses St...
Idealist asked 17/12, 2014 at 9:45

5

Solved

I have searched about this, but I couldn't find why StringBuilder's ensureCapacity() method won't lengthen the old capacity by just doubling but also adding two. So, when default capacity of 16 is...
Bangweulu asked 14/7, 2017 at 4:17

4

var sb = new StringBuilder (); if (condition1) sb.Append ("one"); if (condition2) sb.Append ("two"); if (condition3) sb.Append ("three"); if (condition4) sb.Append ("four"); if (condition5) sb.App...
Oversize asked 19/12, 2014 at 14:25

2

Solved

I've written some code which has a lot of string creation. To try to avoid the expensive string creation over and over, I'm using the java StringBuilder class. My code is a bit like this: public...
Millen asked 12/4, 2018 at 9:14

3

How do I prove programmatically that StringBuilder is not threadsafe? I tried this, but it is not working: public class Threadsafe { public static void main(String[] args) throws InterruptedExce...
Judy asked 1/2, 2018 at 8:37

© 2022 - 2024 — McMap. All rights reserved.