Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

B. The Top Ten Topics that almost made i... > #3 String and StringBuffer/StringBui...

#3 String and StringBuffer/StringBuilder Methods

Two of the most commonly used classes in the Java API are String and StringBuffer (remember from #9 a few pages back, Strings are immutable, so a StringBuffer/StringBuilder can be a lot more efficient if you’re manipulating a String). As of Java 5.0 you should use the StringBuilder class instead of StringBuffer, unless your String manipulations need to be thread-safe, which is not common. Here’s a brief overview of the key methods in these classes:

Both String and StringBuffer/StringBuilder classes have:

char charAt(int index);

// what char is at a certain position

int length();

// how long is this

String substring(int start, int end);

// get a part of this

String toString();

// what’s the String value of this


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial