Get Chars () 

To copy a sub string of h Suffering into an array, use the get Chars( ) method. It has this general form:

Here, scarcest rt specifies the index of the beginning of the sub string, and sourced specifies an index that is one past the end of the desired sub string. This means that the sub string contains the characters from source Start through source End-l. The array that will receive the characters is specified by target. The index within target at which the , sub string will be copied is passed in target Start. Care 'must be taken to assure that the target array is large enough to hold the number of 'characters in the specified sub string.

 append( )

The append( ) method concatenates the string representation of any other type of data to the end of the invoking String Buffer object. It has overloaded versions for all the built-in types and for Object. Here are a few of its forms:

  • String Buffer append bring str)
  • String Buffer append(int num)
  • String Buffer append(Object obj)
  • String value of ()is called for each parameter to obtain its string' representation. The result is appended to the current.
  • String Buffer object. The buffer itself is returned by each version of append( ). This allows subsequent calls to be chained together, as shown in the following example.

The output of this exampled is shown here: a = 42!

The append() method is most often called when the + operator Is.used on String objects. Java automatically changes modifications to a String instance in to similar ' operations on a String Buffer instance. Thus, a concatenation invokes append ) on a String buffer object. After 'the concatenation has been performed, the con compiler inserts a , call to to String( )\to turn the 'modifiable Sling Buffer back into a constant; String. All of this may seem unreasonably complicated. Why not just have one string class and have it behave more or less like String ? The answer is performance. Thee e are many optimizations that the Java run time can make knowing that String objects are
immutable. Thankfully, Java hides most of the complexity of conversion between Strings and String Buffers. Actually, many programmers will never feel the need to- use String Buffer directly and will be able to express most operations in terms of the + operator on String variables,

Share This