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,

Read More

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-595007873ea55460054882/] Params : format - the format string args – Arguments referenced by the format specifiers in the

Read More

String trim example

String trim method is used to remove the leading and trailing white spaces in a String. [crayon-595007873effc811681780/] String trim method example [crayon-595007873f004083442471/] Output [crayon-595007873f00a160374821/] Reference 1. String trim() API

Read More

String concat example

Concat method of String in java is used to add a new String at the end of the original String. [crayon-595007873f3ee272559246/] String concat example [crayon-595007873f3f6566396430/] Output [crayon-595007873f3fc980725735/] Reference 1. String API

Read More

String endsWith example

String endsWith is used to check if a String ends with the given suffix. [crayon-595007873f7e2215569182/] endsWith() method returns a boolean value based on the suffix passed String endsWith example [crayon-595007873f7ea844884244/] Output [crayon-595007873f7f0085590737/] Reference 1. String API

Read More

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-595007873fc25854205140/] [crayon-595007873fc2d689538826-i/] checks if the String starts with the given prefix. [crayon-595007873fc32727484508-i/] checks if the sub

Read More

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-59500787401db369953962/] [crayon-59500787401e5078522035-i/] returns a new String with the oldChar replaced with a newChar that was specified. [crayon-59500787401ea838520765-i/] returns a

Read More

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-59500787409c2559900296/] 1. [crayon-59500787409cc820774353-i/] returns the index of the last occurrence

Read More

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-595007874102b571962726/] 1. [crayon-5950078741034383474507-i/] returns the index of the first occurrence of the specified character. 2. [crayon-5950078741039869698016-i/]

Read More

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-5950078741599534107945/] The first method takes a default Locale for converting the String to upper case, while in the second method we

Read More