String and StringBuffer

Precaution length vs length() vs size() Java

length vs length() vs size(): All the three length, length() and size() give the number of elements present but in different contexts. A) length variable: In Java, array (not java.util.Array) is a predefined class in the language itself. To find the elements of an array, designers used length variable (length…

String Constructors Java

In Java, a String object can be created a number of ways. The most frequently used styles are shown here using 9 types of String constructors (including StringBuffer and StringBuilder) defined java.lang.String API. The 9 constructors are 1. public java.lang.String(); 2. public java.lang.String(java.lang.String); 3. public java.lang.String(char[]); 4. public java.lang.String(char[], int…

String split() Java

Java designers noticed the importance of split() method in a programming language (which already exists in other languages like JavaScript etc.) and introduced in Java from JDK 1.4. The same splitting of a string into independent words or tokens is done in earlier versions using StringTokenizer. Usage of split() in…

String contains() Java

Existence of a substring in the main string can be checked with String contains() method.

Output screen on String contains() Java Existence of a small string (substring) can be checked with indexOf() method also. For other String and StringBuffer API methods check String and StringBuffer.

String Capitalize Java

Java comes with toUpperCase() and toLowerCase() methods that converts all the characters of the string into uppercase or lowercase. String Capitalize example keeps all String characters in capital letters. Following are the method signatures. String toLowerCase(): Converts all the characters of the string into lowercase. Returns a string with all…

String replaceAll() Java

This String class method, replaceAll(), replaces all the occurrences of a word in a string with another word introduced with JDK 1.4 to use with regular expressions. The method returns a new string with affected words. The original string is not disturbed (string is immutable). We discussed a similar program…

Convert StringBuffer to String

After knowing the differences between String, StringBuffer and StringBuilder, let us Convert StringBuffer to String and vice versa. It is very much required in coding. Convert StringBuffer to String A StringBuffer object can be converted to String using toString() method of Object class.

In the above code, equals() method…

One stop destination for all String and StringBuffer

Your one stop destintation for String and StringBuffer operations. 1. String Nature: String are immutable., 2. String Operations: finding matching characters, substring, concatenation & date types conversion to string, uppercase lowercase replacing, Region Matches – Interning – Splitting. 3. StringBuffer Operations: Length and Capacity, Searching Appending and Inserting, Deleting Replacing…

String convert byte array char array

String convert byte array char array Summary: Many a times it is required to convert the string characters into a char array or byte array; of course, very often, the reverse is also required. Discussed at length in this tutorial "String convert byte array char array". Program converting strings to…

byte to String Conversion Example Java

byte To String We know earlier, parsing is the operation on strings to convert into data types. This parsing, we used in command-line arguments and User Password validation. Now we think the other way. Sometimes, it is required to convert data types to string; exactly opposite of parsing. For this…

short to String Conversion Example Java

We know earlier, parsing is the operation on strings to convert into data types. This parsing, we used in command-line arguments and User Password validation. Now we think the other way. Sometimes, it is required to convert data types to string; exactly opposite of parsing. For this purpose, the String…

int to String Conversion Example Java

We know earlier, parsing is the operation on strings to convert into data types. This parsing, we used in command-line arguments and User Password validation. Now we think the other way. Sometimes, it is required to convert data types to string; exactly opposite of parsing. For this purpose, the String…

long to String Conversion Example Java

We know earlier, parsing is the operation on strings to convert into data types. This parsing, we used in command-line arguments and User Password validation. Now we think the other way. Sometimes, it is required to convert data types to string; exactly opposite of parsing. For this purpose, the String…

float to String Conversion Example Java

We know earlier, parsing is the operation on strings to convert into data types. This parsing, we used in command-line arguments and User Password validation. Now we think the other way. Sometimes, it is required to convert data types to string; exactly opposite of parsing. For this purpose, the String…

double to String Conversion Example Java

Summary: By the end of this tutorial "Data type double String Conversion", you will come to know to convert double to string. We know earlier, parsing is the operation on strings to convert into data types. This parsing, we used in command-line arguments and User Password validation. Now we think…

char to String Conversion Example Java

Summary: By the end of this tutorial, "Data type char String Conversion", you will understand converting Java char to string. We know earlier, parsing is the operation on strings to convert into data types. This parsing, we used in command-line arguments and User Password validation. Now we think the other…

boolean to String Conversion Example Java

We know earlier, parsing is the operation on strings to convert into data types. This parsing, we used in command-line arguments and User Password validation. Now we think the other way. Sometimes, it is required to convert data types to string; exactly opposite of parsing. For this purpose, the String…

String vs StringBuffer vs StringBuilder

Three classes exist in java.lang package to manipulate strings – String, StringBuffer and StringBuilder. Even though all the three are used for manipulating strings only but they differ in many aspects and specifically used in the code where demanded. Following tables give the differences between these and when to use.…