• 20 October

    Java Array to Set

    In this post, we will learn java array to set conversion. There are many ways to convert array to set. 1. Using Java 8’s Stream If you are using Java 8, I would recommend using Java 8 Stream. [crayon-6767857913c66880078782/] Output [John, Martin, Mary] 2. Using HashSet constructor() We can directly call HashSet‘s constructor for java […]

  • 10 August

    Java Collection to List

    In this post, we will see how to convert Java Collection to List. There are many ways to do it, we will see two ways here. Using ArrayList constructor [crayon-6767857913ea9189737512/] Above ArrayList‘s constructor creates a list having the elements of the specified collection, in the order they are returned by the collection’s iterator. Using Java […]

  • 09 August

    Java Collections shuffle

    Shuffle method is to permute passed list with default or specified randomness. Syntax [crayon-6767857913f71336745527/] Example : Let’s see both the function with the help of example. [crayon-6767857913f74487397114/] When you run above program, you will get below output: ========================== Before shuffling [John, Martin, Mohan, Mary, Tom] ========================== After shuffling [Mohan, Martin, Mary, Tom, John] ========================== After shuffling […]

  • 24 May

    Collections in java

    In this tutorial, we will see  about Collections in java. Collection framework is core part of java programming language. It is used in almost all the applications. Collections framework provides a way to store and retrieve the collection of elements. This framework has many interfaces and classes which makes programmer life easy. Let’s go through […]

  • 04 November

    How to create list of lists in java

    In this posts, we will see how to create a list of lists in java. You can easily create a list of lists using below syntax List<ArrayList<String>> listOfLists = new ArrayList<ArrayList<String>>(); or ArrayList<ArrayList<String>> listOfLists = new ArrayList<ArrayList<String>>(); One of the Usecase This is generally useful when you are trying to read a CSV file and […]

  • 25 September

    List vs ArrayList in java

    In this post, we will see the difference between List and ArrayList in Java. List is an interface where ArrayList is concrete implementation, so List is more generic than ArrayList. You can instance an ArrayList in below two ways.You might have seen this code before. [crayon-67678579141ee241331060/] If you use 1st way, you can change the […]

  • 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-67678579142c1480229665/] Here is simple example: […]

  • 09 June

    How to find length/size of Arraylist in java

    In this tutorial, we will see how to find length/size of Arraylist in java. You can use ArrayList’size() method to calculate size of ArrayList. Let’s understand it with the help of Simple example. [crayon-67678579143ba679498825/] When you run above program, you will get below output: Size of Country List is: 4 [India, China, Bhutan, Nepal] Size […]

  • 03 June

    Convert HashMap to ArrayList in java

    In this post, we will see how to convert HashMap to ArrayList in java. Many times, you need to store keys or values into ArrayList or Store HashMap’s Node objects in ArrayList. HashMap and ArrayList both are the most used data structure in java and both have different Hierarchy. Here are the ways to convert […]