• 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-6629ce961c83c256677166/] 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-6629ce961d0e9697549390/] 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-6629ce961d8ca841082959/] str1.equalsIgnoreCase(str2) will return true. Method Signature: [crayon-6629ce961d8d0520472858/] String equalsIgnoreCase Example: [crayon-6629ce961d8d1755613515/] When you run above program, you will get below output: [crayon-6629ce961d8d2058441092/]

  • 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-6629ce961d9d7762645676/] String equals Example: [crayon-6629ce961d9da056044204/] When you run above program, you will get below output: [crayon-6629ce961d9db037740692/]

  • 14 May

    Java String contentEquals example

    String’s contentEquals method is used to compare String with StringBuffer. It returns boolean datatype. Method syntax: [crayon-6629ce961da81078052779/] String contentEquals Example: [crayon-6629ce961da83767699769/] When you run above program, you will get below output: [crayon-6629ce961da84803714992/] 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-6629ce961e01e165630635/] String endsWith Example: [crayon-6629ce961e024352213961/] When you run above program, you will get below output: [crayon-6629ce961e025486437500/] 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-6629ce961e58b362718688/] String startsWith Example: [crayon-6629ce961e590661679705/] When you run above program, you will get below output: [crayon-6629ce961e591791911300/] 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-6629ce961e6be615565840/] String charAt Example: [crayon-6629ce961e6c2675672225/] When you run above program, you will get below output: [crayon-6629ce961e6c3701632202/]