StringBuilder s = new StringBuilder("Hello
Mom");s.append(",I mean,Mother");
Response.Write(s.ToString());
String s = "Hello Mom";
s+ = ",I mean Mom";
Response.Write(s);
Which is faster ? which uses the most memory?
Answer Posted / jimmy dean
The second one is faster.
In the first example the StringBuilder is initialized with
an initial value. Then the append method is ran, adding
another string to 's'. Then the Write method is called,
which calls the ToString() method of 's'.
Total Steps:
1.) Initialize and set initial value
2.) Append
3.) Write
4.) ToString()
In the second example the String is initialized with an
initial value. Then a string is added onto 's'. Then the
Write method is called.
Total Steps:
1.) Initialize and set initial value
2.) Add String to String
3.) Write
Therefore I would say that the second example is faster, and
uses less memory.
| Is This Answer Correct ? | 0 Yes | 3 No |
Post New Answer View All Answers
What is the largest number a double can hold?
What is variable length arguments in java?
Why map is used in java?
Does string is thread-safe in java?
Describe the process as to how substring() methodology mechanisms in java.
Is java a super set of javascript?
What is the difference between an interface and an abstract class?
How to solve the problem of generating the unique hash keys with hash function?
What is the difference between a choice and a list?
How to sort an unsorted array in java?
How do you sort objects in java?
What are the three types of design patterns?
What is arrays fill in java?
Explain the overview of UDP messaging.
What is return data type?