Difference String StringBuffer and StringBuilder

We will see the differences between String, StringBuffer and StringBuilder. The main differences are related to thread safe nature and performance. Difference String StringBuffer and StringBuilder String 1. String is immutable – So string is Thread Safe. 2. Any operations on String,
String.format java example

In this post we will see String.format java examples. Format method in String returns a formatted string using the specified format string and arguments. [crayon-5ad939776dd04254363391/] Params : format - the format string args – Arguments referenced by the format specifiers in the
String trim example

String trim method is used to remove the leading and trailing white spaces in a String. [crayon-5ad939776e29c329538094/] String trim method example [crayon-5ad939776e2a4324297359/] Output [crayon-5ad939776e2aa749562494/] Reference 1. String trim() API
String concat example

Concat method of String in java is used to add a new String at the end of the original String. [crayon-5ad939776e6c2896373726/] String concat example [crayon-5ad939776e6ca851312394/] Output [crayon-5ad939776e6d0118085477/] Reference 1. String API
String endsWith example

String endsWith is used to check if a String ends with the given suffix. [crayon-5ad939776ead2223966312/] endsWith() method returns a boolean value based on the suffix passed String endsWith example [crayon-5ad939776eadb030429163/] Output [crayon-5ad939776eae1196764970/] Reference 1. String API
String startsWith example

String startsWith method is used to check if a String starts with a specified substring. Startswith method has 2 variations and we will see both these. [crayon-5ad939776ef26471882383/] [crayon-5ad939776ef2f989451094-i/] checks if the String starts with the given prefix. [crayon-5ad939776ef34455607496-i/] checks if the sub
String replace methods example

String replace methods are used to replace a part of string with a new string. We have 4 variations for replace in String [crayon-5ad939776f4fc107743504/] [crayon-5ad939776f50a932265883-i/] returns a new String with the oldChar replaced with a newChar that was specified. [crayon-5ad939776f510728946387-i/] returns a
String lastIndexOf example

String lastIndexOf returns the index of the last occurrence of the given String for specified conditions searching backward. String lastIndexOf method can be used with multiple types of parameters as shown below [crayon-5ad939776fc94403104717/] 1. [crayon-5ad939776fc9c140692149-i/] returns the index of the last occurrence
String indexOf example

String indexOf returns the index of the given String for specified conditions. String indexOf method can be used with multiple types of parameters as shown below [crayon-5ad9397770285795360424/] 1. [crayon-5ad939777028e037659492-i/] returns the index of the first occurrence of the specified character. 2. [crayon-5ad9397770294830787223-i/]
String toUpperCase example

String toUpperCase method is used to converts all characters in a given string to upper case. String has 2 toUpperCase methods. [crayon-5ad939777084d084148931/] The first method takes a default Locale for converting the String to upper case, while in the second method we