Java String

String Concatenation Using Plus Operator

Java String Concatenation

Java String concatenation is the process of creating a new string by combining two or more strings. The String is the only class that supports “+” operator for string concatenation. We can also use String class concat() method to concatenate two strings. If we use + operator with String and primitive types, then the output …

Java String Concatenation Read More »

Java StringBuilder Class

Java StringBuilder class is used to manipulate string objects. StringBuilder is a mutable sequence of characters. StringBuilder was introduced in Java 1.5 StringBuilder methods are not thread-safe, so it’s recommended for the single-threaded environment. You should use StringBuffer in a multithreaded environment for thread safety. Some of the common operations StringBuilder provides are – append, insert, …

Java StringBuilder Class Read More »

Java StringBuffer Class

Java StringBuffer class is used to manipulate string objects. StringBuffer is a thread-safe mutable sequence of characters. StringBuffer methods are synchronized, so it’s advised to use it for string manipulation in a multithreaded environment. Some of the common operations StringBuffer provides are – append, insert, reverse, and delete. StringBuilder class was introduced in Java 1.5, …

Java StringBuffer Class Read More »

Java String Array

Java String array is used to store a fixed number of string objects. String arrays are used a lot in Java programs. Even the Java main method parameter is a string array. The common use cases are – read CSV data into a string array, read text file lines into a string array. How to …

Java String Array Read More »

Java String equalsIgnoreCase() Method

Java String equalsIgnoreCase() method compares this string with the argument string without case consideration. This method returns true if both the strings have the same character sequence, ignoring their case. String equalsIgnoreCase() Method Implementation The equalsIgnoreCase() method is implemented like this. The Logic for Characters Comparison Ignoring Case The two characters c1 and c2 are …

Java String equalsIgnoreCase() Method Read More »

Java String contentEquals() Method Examples

Java String contentEquals() method returns true if this string has the same character sequence as the method argument. String contentEquals() Method Signatures There are two overloaded version of contentEquals() method. public boolean contentEquals(CharSequence cs): The string object content is compared with the CharSequence argument. If the character sequence is exactly the same, then this method …

Java String contentEquals() Method Examples Read More »