• 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-6729e405a1474126931831/] 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-6729e405a1933774300164/] 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-6729e405a2952458331519/] str1.equalsIgnoreCase(str2) will return true. Method Signature: [crayon-6729e405a295a493177172/] String equalsIgnoreCase Example: [crayon-6729e405a295b912979401/] When you run above program, you will get below output: [crayon-6729e405a295d406666250/]

  • 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-6729e405a343b103320106/] String equals Example: [crayon-6729e405a3445105076209/] When you run above program, you will get below output: [crayon-6729e405a3446886041284/]

  • 14 May

    Java String contentEquals example

    String’s contentEquals method is used to compare String with StringBuffer. It returns boolean datatype. Method syntax: [crayon-6729e405a35bf266315759/] String contentEquals Example: [crayon-6729e405a35c6162190547/] When you run above program, you will get below output: [crayon-6729e405a35c8235784428/] 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-6729e405a36e2057680603/] String endsWith Example: [crayon-6729e405a36e5766243008/] When you run above program, you will get below output: [crayon-6729e405a36e7105512846/] 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-6729e405a3daa089934217/] String startsWith Example: [crayon-6729e405a3db0532443919/] When you run above program, you will get below output: [crayon-6729e405a3db1756980101/] 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-6729e405a5e9e054537169/] String charAt Example: [crayon-6729e405a5eab570554610/] When you run above program, you will get below output: [crayon-6729e405a5ead626433132/]