• 24 September

    How to convert List to Set in java

    In this post, we will see how to convert List to Set in java.We will convert ArrayList to HashSet. As HashSet does not allow duplicates, when you convert ArrayList to HashSet, all the duplicates will be discarded. You can simply use the constructor of HashSet to convert ArrayList to HashSet. [crayon-61a2bf14723de272395932/] Here is simple example: […]

  • 21 October

    How to convert Byte Array to String in java

    Sometimes, we may need to convert String to bytes Array but how to convert bytes array to String back. toString method does not work correctly here as it just print bytes in String format. You can use String’s constructor to get String back. Example: [crayon-61a2bf14743b7285314163/] When you run above program, you will get below output: […]

  • 24 May

    How to convert String to Byte array in java

    Sometimes, we need to convert String to byte array. We can use getBytes() method of String to do it, Method syntax: [crayon-61a2bf147576a659433666/] String getBytes Example: [crayon-61a2bf147577a229950013/] When you run above program, you will get below output: [crayon-61a2bf147577f836984195/] There is one more overloaded method for getBytes Method syntax: [crayon-61a2bf1475785499471626/] It encodes String to specified charset format. […]

  • 04 May

    How to convert String to Char Array in java

    Java String’s toCharArray() method can be used to convert String to char Array in java. It is simplest method to convert String to char Array. Example: [crayon-61a2bf1476fcd148897486/] When you run above program, you will get below output: [crayon-61a2bf1476fdd561224731/] Other String Programs are : String : How to reverse String in java How to check if […]

  • 04 May

    How to convert Char Array to String in java

    There are multiple ways to convert Char Array to String in java. Some of them are: Using String class’s constructor (By passing Char array to contructor) Using String class’s valueOf method Using iterating char array Example: [crayon-61a2bf147817f886384571/] When you run above program, you will get below output [crayon-61a2bf147818e780848296/] Other String Programs are : How to […]