String
- 18 May
How to remove all white spaces from String in java
In this post, we will see how to remove all white spaces from String in java. There are multiple ways to remove spaces from String. Using ReplaceAll Using Iteration Using ReplaceAll : You can simply call ReplaceAll method to remove white spaces as shown below. [crayon-67510c1899a52079347735/] Using iteration : You can iterate over String using […]
- 17 May
How to check if one String is rotation of another String in java
In this post, we will see how to check if one String is rotation of another or not. For example: [crayon-67510c1899cd3385459647/] Approach: Lets say you need to check whether str1 and str2 is rotation of one another or not. Create a new String with str3= str1 + str1 Check if str3 contains str2 or not. […]
- 15 May
Java String compareToIgnoreCase example
String’s compareToIgnoreCase method is similar to compareTo method. Only difference with compareTo is that it ignores cases.It also compares Strings lexigraphically. Both String get converted to unicode value and then compares. If you call str1. compareToIgnoreCase(str2) then if it returns positive number : str1 is greater than str2 0: str1 is equal to str2 negative number : str1 is […]
- 14 May
Java String equalsIgnoreCase example
String’s equalsIgnoreCase method is similar to equals method but it ignores case. So if Strings have different cases, then also it will considered as equals. For example: [crayon-67510c1899eb2086476742/] str1.equalsIgnoreCase(str2) will return true. Method Signature: [crayon-67510c1899eb5970616135/] String equalsIgnoreCase Example: [crayon-67510c1899eb6197364530/] When you run above program, you will get below output: [crayon-67510c1899eb7383176399/]
- 14 May
Java String equals example
String’s equals method compares String with specified object. It checks if both have same character sequence. It is generally used to compare two Strings. Method Signature: [crayon-67510c1899f5b302811204/] String equals Example: [crayon-67510c1899f5e637280226/] When you run above program, you will get below output: [crayon-67510c1899f5f135575702/]
- 14 May
Java String contentEquals example
String’s contentEquals method is used to compare String with StringBuffer. It returns boolean datatype. Method syntax: [crayon-67510c1899ff7742278882/] String contentEquals Example: [crayon-67510c1899ff9492924760/] When you run above program, you will get below output: [crayon-67510c1899ffa727964422/] Please note that contentEquals method is case sensitive as you can see in above example
- 13 May
Java String endsWith example
String’s endWith method checks if String ends with specific suffix. It returns boolean datatype. Method syntax: [crayon-67510c189a09a767517929/] String endsWith Example: [crayon-67510c189a09c912211346/] When you run above program, you will get below output: [crayon-67510c189a09d664609629/] Please note that endsWith method is case sensitive as you can see in above example
- 12 May
Java String startsWith example
String’s startsWith method checks if String starts with specific prefix. It returns boolean datatype. Method Signature: [crayon-67510c189a155847219590/] String startsWith Example: [crayon-67510c189a158627534723/] When you run above program, you will get below output: [crayon-67510c189a159439497131/] Please note that startsWith method is case sensitive as you can see in above example
- 12 May
Java String charAt example
String’s charAt method returns char value present at specified index. String is nothing but Sequence of char values and it starts with index 0. Method Signature: [crayon-67510c189a1f4716332494/] String charAt Example: [crayon-67510c189a1f7954137233/] When you run above program, you will get below output: [crayon-67510c189a1f8249872258/]