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 is a field member in …

Precaution length vs length() vs size() Java Read More »

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 startIndex, int numChars); 5. public …

String Constructors Java Read More »

String contains() Java

Existence of a substring in the main string can be checked with String contains() method. public class Demo { public static void main(String args[]) { String str1 = “abcdefghi”; // string (main string) String str2 = “def”; // another string (substring) String str3 = “ded”; // another string (substring) boolean b = str1.contains(str2); // checks …

String contains() Java Read More »

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 lowercase letters. Remember, the original …

String Capitalize Java Read More »

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. StringBuffer sb1 = new StringBuffer(“hello”); StringBuffer sb2 = new StringBuffer(“hello”); String str1 …

Convert StringBuffer to String Read More »

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 and Palindrome, Petty Methods and …

One stop destination for all String and StringBuffer Read More »

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 char array and byte array …

String convert byte array char array Read More »

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 purpose, the String class comes …

byte to String Conversion Example Java Read More »

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 class comes with valueOf() static …

short to String Conversion Example Java Read More »

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 class comes with valueOf() static …

int to String Conversion Example Java Read More »

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 class comes with valueOf() static …

long to String Conversion Example Java Read More »

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 class comes wit.h valueOf() static …

float to String Conversion Example Java Read More »

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 the other way. Sometimes, it …

double to String Conversion Example Java Read More »

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 way. Sometimes, it is required …

char to String Conversion Example Java Read More »

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 class comes with valueOf() static …

boolean to String Conversion Example Java Read More »

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. Now let us tabulate the …

String vs StringBuffer vs StringBuilder Read More »