Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementation of Stringobject and StringBuffer object

 
Venkat Ramsimha
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

Can anybody tell me the implementation of 'Stringobject' and 'StringBuffer object'alongwith its functionality and usage in the program


looking forward

tx
venkat(hunt:scjp1.4)
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um .... right. You can download the source code for the JDK and look at String and StringBuffer's implementation if you really want, for some bizarre reason.
 
Krishna Srinivasan
Ranch Hand
Posts: 1862
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
I think these links will help you.
StringBuffer
String and StringBuffer
 
Krishna Srinivasan
Ranch Hand
Posts: 1862
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
I hope these links will help you.
StringBuffer
String and StringBuffer
 
Rob Harris
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you know which methods belong to String, e.g., concat() and which to StringBuffer, e.g., append(). Remember that the substring(int beginIndex, int endIndex) uses a zero-based beginIndex but starts with 1 for the endIndex - (and has en evil lower-case 's' in substring).

But most of all, understand the difference between Strings - immutable objects - and StringBuffers - not-so-immutable objects.
i.e.:
String s = new String ("Java");
s.concat(" Rules!");
System.out.println(s);
StringBuffer sb = new StringBuffer("Java");
s.append(" Rocks!");
System.out.println(sb);

output:
Java
Java Rocks

why?
The line of code
s.concat(" Rules!");
created a new String "Java Rules!", but didn't attach a reference to it!

Have fun.

Rob
SCJP 1.4
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic