String and StringBuffer

Java String Immutable Comparison

Java String Immutable Comparison Summary: At the end of this tutorial "Java String Immutable Comparison", you will understand the meaning of immutable. Also you will come to know the styles of comparing Java strings. String handling and string manipulation play a vital role in programming. The simplicity in handling makes…

substring() Extract Part of a String

Here, we use the overloaded methods of substring() to extract the whole or a part of a string. Following is the signature of overloaded substring() method as defined in String class. String substring(int indexNum): Returns a string containing all the characters existing from indexNum to the end in the given…

Convert Data type Java String

Convert Data type Java String Summary: Many a times, it is required in Java coding to convert string to data types or data types to string. This tutorial "Convert Data type Java String" does this job. In parsing operations, we convert strings into data types. Sometimes, code demands to convert…

regionMatches() and intern() String Java

The String class is rich with abundant methods used in coding. One of the methods is overloaded regionMatches() used to find the existence of a few characters of one string in another. Supported methods from String class. boolean regionMatches(int positionFirstString, String secondString, int positionSecondString, int num): Returns a boolean value…

Search, Append and Insert StringBuffer Methods

Very often used many StringBuffer Methods are discussed with Examples and Screenshots in Simple terms for a Beginner. StringBuffer Methods for Searching characters The indexOf(), lastIndexOf() and charAt() methods existing in String class also exist in StringBuffer class. They can be used with StringBuffer object. The meaning of the methods…

StringBuffer substring Java Pass By Reference

StringBuffer substring Java Pass By Reference Many petty methods exist with StringBuffer like substring(), setLength() and trimToSize() etc. These methods are not much used in regular programming.

Output screen of MiscellaneousMethods.java of StringBuffer substring Java Pass By Reference substring() method works the same way of strings. setLength() and trimTosize()…

Concatenation – Conversion

We know earlier, the + operator is implicitly overloaded in Java – works for addition and concatenation. For concatenation, String class includes concat() method. That is, strings can be concatenated both with + operator an concat() method. Following program illustrates.

String s4 = s1+s2+s3; String s5 = s1.concat(s2); String…

Palindrome Delete Replace Reverse Java Example

Note: Palindrome Example is available in second page. 1. Deleting the Characters To delete characters from StringBuffer, two methods exist – deleteCharAt() and delete(). Supported methods from String class StringBuffer deleteCharAt(int pos): Delete the character in the StringBuffer at the specified index number, pos. StringBuffer delete(int start, int end): Deletes…

Java String Find matching characters indexOf(), lastIndexOf()

To Java String find matching, we use three methods – overloaded indexOf() and lastIndexOf() and charAt(). Index numbers are given by the JVM implicitly to the characters in the string; the first character is given 0, the second one as 1 and so on. These index numbers are helpful in…

toUpperCase(), toLowerCase() and replace() String

Here, we do some miscellaneous operations on strings like converting a string from lowercase to uppercase or vice versa, removing unwanted prefix and suffix whitespaces and replacing a few characters with replace() String. Supported methods from String class. String toLowerCase(): Returns a new string containing all lowercase characters. All the…

length() and capacity() Example StringBuffer

An example on StringBuffer methods length() and capacity() is given in Simple terms for a Beginner. Finding length() and capacity() In Java coding, the programmer should be aware of not only methods of a class but also constructors. Constructors give the properties for an object at the time of creation…