ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
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?
 Question Submitted By :: Chinna Reddy
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
The StringBuilder one is slightly more efficient and uses
less memory. In practice, it is unlikely to make enough of a
difference to matter either way.
 
Is This Answer Correct ?    0 Yes 1 No
Parameswaran M
 
  Re: 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
# 2
The first one is faster

Second code snippets:3 objects are created

1:s = "Hello Mom"
2:,I mean Mom
3:Hello Mom,I mean Mom
 
Is This Answer Correct ?    2 Yes 2 No
Debapriya Maity
 
 
 
  Re: 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
# 3
The first one is faster

Second code snippets:3 objects are created

1:s = "Hello Mom"
2:,I mean Mom
3:Hello Mom,I mean Mom
 
Is This Answer Correct ?    3 Yes 1 No
Debapriya Maity
 
  Re: 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
# 4
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 1 No
Jimmy Dean
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
What is the USE of Null interfaces ??...if thers nothing inside these interfaces how are they used and WHy are they used ???? No 1 has given a proper description yet  1
can we write a program with out a class in core java? Wipro5
What is the need to implement Serializable interface (with no methods) for objects which are to be serialized ? We can write our own functionality which writes objects to streams then why we need to implement and tell JVM that which objects can be serialized. iFlex4
How 'java' got its name and what it stands for?  5
What is the difference between jsp and servlet? Symphony5
If set accepts only one argument then how can it compare two objects to avoid duplicates  3
what is tempplate pattern RBS4
What do you mean by the term transient? Ericsson4
When will we use class loader?  1
"We cannot create an object of interface but we can create a variable of it". Discuss the statement with the help of an example. (Plz help us to provide immediately.)  1
What is Collections API?  1
Hi ,i convert contrller as jSp And presentation as servlet ...will it do? if so what are advantage and idsadvantages IBM1
What are other modifiers? Wipro1
What restrictions are placed on method overloading and method overriding?  3
What is the difference between Abstract Class and Interface AMDOC6
Define interface?  2
what is bytecode? watz the difference between machine code and bytecode? Oracle4
What are command line arguments?  2
What is JIT ? Satyam4
What is the diff. b/w Interfaces & Abstract class? Ericsson4
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com