• 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-6605b6f81de7e811191856/] String equals Example: [crayon-6605b6f81de96163081765/] When you run above program, you will get below output: [crayon-6605b6f81de97562502574/]

  • 14 May

    Java String contentEquals example

    String’s contentEquals method is used to compare String with StringBuffer. It returns boolean datatype. Method syntax: [crayon-6605b6f821292659216881/] String contentEquals Example: [crayon-6605b6f821299948772791/] When you run above program, you will get below output: [crayon-6605b6f82129a550590421/] 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-6605b6f821d0e939519202/] String endsWith Example: [crayon-6605b6f821d15592744087/] When you run above program, you will get below output: [crayon-6605b6f821d16957939895/] 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-6605b6f823c4f420150929/] String startsWith Example: [crayon-6605b6f823c57862486063/] When you run above program, you will get below output: [crayon-6605b6f823c59981723583/] 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-6605b6f8258de030911183/] String charAt Example: [crayon-6605b6f8258e6827885320/] When you run above program, you will get below output: [crayon-6605b6f8258e8348499046/]

  • 11 May

    Java String trim example

    String’s trim method is used to remove leading and trailing space. Sometimes, you get extra leading or trailing space and your program does not work as expected. It returns String object after removing leading and trailing spaces. String’s trim method does not remove middle spaces. String trim example: [crayon-6605b6f826716091215905/] When you run above program, you […]

  • 10 May

    How to check if two Strings are Anagrams in Java

    In this post, we will see how to check if two Strings are Anagrams in java. Anagrams mean if two Strings have the same characters but in a different order. For example: Angel and Angle are anagrams There are many ways to check if Strings are anagrams in java. Some of them are: Using String […]

  • 10 May

    Java String regionMatches example

    String’s regionMatches is used to compare substring of one string to substring of another.Here region may be refer to substring of String, so we are comparing regions of one string with another. Method Syntax:  There are two overloaded version of regionMatches: [crayon-6605b6f828064104848170/] Parameters: ignoreCase: It is boolean field to indicate whether to ignore case or […]

  • 10 May

    Java String isEmpty example

    String’s isEmpty method checks if length of string is 0 or not. It returns true if length of String is 0 else return false. Method Signature: [crayon-6605b6f828e99499214856/] String isEmpty Example: [crayon-6605b6f828e9f281141841/] When you run above program, you will get below output: [crayon-6605b6f828ea1008092242/]