View RSS Feed

StringBuffer

Java StringBuffer

  1. Using Regular Expressions with String.matches()

    by , 04-26-2012 at 06:44 PM
    Built in support is provided by Strings present in Java for the regular expressions. There are 3 built in methods present in Strings for regular expressions. For example: replace(), split() and matches().

    There is no optimization of methods for performance. Classes will be used later on, which are performance optimized.

    s.matches("regex"): Evaluates if "regex" matches s. Returns only true if the WHOLE string can be matched
    s.split("regex") ...
    Categories
    StringBuffer
  2. Regular Expressions Overview

    by , 04-26-2012 at 06:42 PM
    For strings, search pattern is defined by the regular expression. Such kind of pattern might be matching one time or several times, or not at all. Regular expression has an abbreviation “regex”.
    String (literal) is a simpler example of regular expression. E.g. Hello World string will be matched with Hello World regex.

    Other regular expression example is (dot) “.” That match with just one single character; and it will be matching e.g. “z”or ”a” or ”1”.

    Usage ...
  3. Memory usage of StringBuilder and StringBuffer

    by , 04-26-2012 at 06:39 PM
    The implementation of these classes is essentially done in similar manner through the shared subclasses & usage of their memory is also same. Difference comes when the turn of those methods come that are present at StringBuffer get synchronized. Here they will be referred as the string buffers generically for sake of simplicity however; comment at the usage of memory will be applied to both classes.

    Object’s overhead is required by the string buffer, space for sake of int field ...
  4. StringBuffer Functions

    by , 04-26-2012 at 06:38 PM
    Few StringBuffer methods has many uses which is being explained by the following program:

    1. capacity()
    String buffer’s current capacity is returned.

    2. length()
    String buffer’s length is returned.

    3. charAt(int index)
    Specified sequence character which is presented by string buffer are returned.

    4. setCharAt(int index, char ch)
    At specified index, the character of this string buffer has been set to ch
    ...
  5. StringBuffer

    by , 04-26-2012 at 06:36 PM
    Thread safed & mutable character sequence. Basically it is just like String however modifications could be done with it. At any time, few specified character sequences are present in it but the content or length of that sequence might be changed via method calls.

    Mutilple threads may use string buffers safely. Synchronization of methods is done where it is considered to be an important thing hence all operations that take place at some specific instance would behave like they ...
    Tags: stringbuffer Add / Edit Tags
    Categories
    StringBuffer
  6. String vs. StringBuffer

    by , 01-08-2012 at 11:26 AM
    Following are the major differences between these 2:

    • String is immutable as compared to StringBuffer. You need to create a new instance to replace an object.

    Java Code: This is an example of immutable string
    //Inefficient version using immutable String
    String output = “Some text”
    Int count = 100;
    for(int I =0; i<count; i++) {
    output += i;
    }
    return output;
    • StringBuffer is mutable. Also it is not synchronized.

    Java Code: This is an example of mutable string
    //More
    ...

    Updated 01-14-2012 at 06:42 PM by Java String

    Categories
    String , StringBuffer