• 09 May

    Java String length example

    String’s length method is used to calculate length of String. It returns number of character in the String. Method Signature: [crayon-662b6b46abb72498168678/] String length Example: [crayon-662b6b46abb7a113792712/] When you run above program, you will get below output: [crayon-662b6b46abb7c436607465/]

  • 08 May

    Java Program to find duplicate Characters in a String

    In this post, we will see how to find duplicate Characters in a String. Approach: Create a HashMap and character of String will be inserted as key and its count as value. If Hashamap already contains char,increase its count by 1, else put char in HashMap If value of Char is more than 1, that means it […]

  • Java String join
    08 May

    Java String join example

    String’s join method can be used to join various String by the delimiter. It is introduced in java 8. For example: We need to join various Strings by “,”. You can use join method as [crayon-662b6b46aca77318848557/] There are two overloaded variants of String’s join method: [crayon-662b6b46aca7d149993213/] String join example: [crayon-662b6b46aca7e396306415/] When you run above program, […]

  • 07 May

    Why String is immutable in java

    String class is immutable in java. If you take dictionary meaning of immutable, it means unable to be changed or unchanging over time, so String is unchangeable or unmodifiable in java. Let’s understand with example. [crayon-662b6b46acfa9281438022/] As you can see, value of str1 did not change. It created another String object with value “Hellojava2blog” but […]

  • 07 May

    Java String lastIndexOf example

    String’s lastIndexOf method is used to find out last index of any character or sub string. lastIndexOf method can take char or string as argument and also you can provide fromIndex also. Methods: public int lastIndexOf(int ch) returns index of last occurrence of character within String public int lastIndexOf(int ch,int fromIndex) returns index of last occurrence […]

  • 07 May

    Java String indexOf example

    String’s indexOf method is used to find out index of any character or sub string. indexOf method can take char or string as argument and also you can provide fromIndex(Index after which you want to use indexOf method) also. Methods: public int indexOf(int ch) returns index of first occurrence of character within String public int […]

  • 06 May

    Java String substring example

    String’s substring method is used to fetch part of a String.It returns a new String which is substring of given String. substring is nothing but subset of given String. There are two overloaded methods for substring. Method Signature: [crayon-662b6b46adcac197664950/] It returns a new String which is substring of given String from specified startIndex(Inclusive) [crayon-662b6b46adcb1019897332/] It […]

  • 06 May

    Java String contains example

    String’s contains method checks if sequence of characters can be found in String. It returns true if character sequence is present in String else return false. Method Signature: [crayon-662b6b46ae17a850258034/] String contains Example: [crayon-662b6b46ae17e617271115/] When you run above program, you will get below output: [crayon-662b6b46ae180241398260/] Please note that contains method is case sensitive as you can […]

  • 06 May

    Java String concatenate example

    String concatenate is a way to join multiple Strings to create large String. There are many places where we use to do String concatenate. For example: When you override toString() method of object, you concatenate multiple attributes to create a big String that represent that object. 3 ways to concatenate String Using + operator Using String’s […]