Ask a Teacher



What are library classes. What are Character Functions,String Functions,String Buffer Functions.

Library Classes of Java . Pr-defined classes of java which get included in an application program itself are called library classes.They are also known as standard java classes or built in java classes.These classes also have built in member variables,constructors and methods like ordinary classes developed by programmer.These library classes are contained in packages.

In Java strings are objects designed to represent a sequence of characters.  Because
character strings are commonly used in programs, Java supports the ability to declare String
constants and perform concatenation of Strings directly without requiring access to methods of theString class.  This additional support provided for Java Strings allows programmers to use Strings in a similar manner as other common programming languages.

A Java String is read-only and once created the contents cannot be modified.

The StringBuffer class is used to represent characters that can be modified. This is simply used for concatenation or manipulation of the strings.

tringBuffer is mainly used for the dynamic string concatenation which enhances the performance. A string buffer implements a mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls. There are some functions used in the given example. All the functions have been explained below with example :

append()

This is the append() function used for the concatenate the string in string buffer. This is better to use for dynamic string concatenation. This function works like a simple string concatenation such as : String str = str + "added string";.

insert()

This is the insert() function used to insert any string or character at the specified position in the given string.

reverse()

This is the reverse() function used to reverse the string present in string buffer.

setCharAt()

This is the setCharAt() function which is used to set the specified character in buffered string at the specified position of the string in which you have to set the given character.

charAt()

This is the charAt() function which is used to get the character at the specified position of the given string.

substring()

This is the substring() function which is used to get the sub string from the buffered string from the initial position to end position (these are fixed by you in the program).

deleteCharAt()

This is the deleteCharAt() function which is used to delete the specific character from the buffered string by mentioning that's position in the string.

length()

This is the length() function is used to finding the length of the buffered string.

delete()

This is the delete() function is used to delete multiple character at once from n position to m position (n and m are will be fixed by you.) in the buffered string.

capacity()

This is the capacity() function is used to know about the current characters kept which is displayed like : number of characters + 6.



comments powered by Disqus