by Dinesh Thakur Category: array
 
by Dinesh Thakur Category: array

The String class includes several methods that compare strings or substrings within strings. To perform a comparison that ignores case differences, use equalsIgnoreCase(). This method considers lowercase and upper case characters as same while comparing strings. That is, it considers A-Z to be the same as a-z.

 
by Dinesh Thakur Category: array

Java does not allow operators to be applied to String objects. The one exception to this rule is the + operator, which concatenates two strings, producing a String object as the result. We can also concatenate strings with other types of data after converting them into strings. Java converts other data types into its string representation by calling valueOf() defined by String. For the simple types, valueOf() returns a string equivalent of the value with which it is called. For objects, valueOf()calls the toString() method on the object.



 
by Dinesh Thakur Category: array

Matrix addition means addition of respective positions. That is, element of 0th row 0th column of first matrix will be added with 0th row and 0th column of second matrix and placed in resultant matrix at 0th row and 0th column position. And this way all the element positions of first matrix are added with the respective positions of second matrix and stored in resultant matrix at the same position.

 
by Dinesh Thakur Category: array
 
by Dinesh Thakur Category: array
 
by Dinesh Thakur Category: array

Elements that can be added to the Vector must be of type java .lang. Object. In other words, vectors cannot handle primitive data typeslike int, float, char and double as they are not objects. So in order to work with primitive type variables as if they were objects, Java provides class for each of the primitive types. These classes are known as wrapper classes.



 
by Dinesh Thakur Category: array

Arrays have fixed length, they are not suitable for group of things that grow and shrink over the lifetime of an application. In such situations, Java provides the Vector class which is available in the standard java.util package.



 
by Dinesh Thakur Category: array

StringBuffer deleteCharAt (int index): This method deletes the character at the specified position index from the string buffer. For example,

 
by Dinesh Thakur Category: array

StringBuffer delete (int start, int end): This method is used to remove a sequence of characters from the StringBuffer object. The start represents the index of the first character to be deleted and end represents the index of one past the last character to remove. Therefore, the deleted substring runs from start to end -1. For example,

 
by Dinesh Thakur Category: array

StringBuffer insert (int index, char [] str, int offset, int len) :This method inserts a substring into the StringBuffer object starting at position index. The substring is the string representation of len characters from the str []array starting at index position offset.

 
by Dinesh Thakur Category: array

StringBuffer append(char[] str,int offset,int len) :This method appends the substring to the end of the string buffer. The substring appended is a character sequence beginning at the index offset with the number of characters appended equal to len of the character array str. For example,

 
by Dinesh Thakur Category: array

String toString () : This method returns the value of the invoking StringBuffer object that invoked the method as a string. For example: The statement,

 
by Dinesh Thakur Category: array

void setCharAt (int index, char ch) : This method sets the character at the specified index in the string buffer to the new character ch. For example, s1. setCharAt (6, 'J') will return Hello Java.

 
by Dinesh Thakur Category: array

String substring (int beginIndex) : This method returns a substring of the invoking StringBuffer. The substring returned contains a copy of characters beginning from the specified index position beginIndex and extends to the end of the string. For example, s1. substring (3) returns the substring lo Java.

 
by Dinesh Thakur Category: array

char charAt (int index) : This method returns the character in the string buffer at the specified index position. The index of the first character is 0, the second character is 1 and that of the last character is one less than the string buffer length. The index argument specified must be greater than or equal to 0 and less than the length of the string buffer. For example, strl.charAt(1) will return character e i.e. character at the index position 1 on the StringBuffer str1.

 
by Dinesh Thakur Category: array

void setLength(int newLength) : This method sets (change) the length of the string contained in the StringBuffer object. If the newly specified length is less than the current length of the string buffer, then the string buffer is truncated to contain exactly the number of characters contained in the newlength parameter. If the specified argument is greater than or equal to the current length, sufficient null characters (‘\ u0000') are appended to the string buffer until the total number of characters in the string buffer is equal to the specified length. For example, if following is part of a statement, strl.setLength(10) As a result of this, the string referenced by strl will now contain "Welcome\u0000\u0000\u0000" Similarly, strl. setLength (5) will result in “Hell" .

 
by Dinesh Thakur Category: array

int length (): This method returns the number of characters currently in the invoking string buffer. For example,

 
by Dinesh Thakur Category: array

int capacity () : This method returns the current capacity of the string buffer i.e. number of characters it is able to store without allocating more memory. While discussing capacity () methods, we assume that the StringBuffer object str1 exists which is defined as follows,

 

Page 2 of 5



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles