• 02 October

    Initialize ArrayList with values in Java

    In this article, we will learn to initialize ArrayList with values in Java. ArrayList is an implementation class of List interface in Java. It is used to store elements. It is based on a dynamic array concept that grows accordingly. We can Initialize ArrayList with values in several ways. Let’s see some of them with […]

  • 15 April

    How to Deep Copy Arraylist in Java

    Learn about how to create deep copy of ArrayList in different ways.

  • 17 March

    PriorityQueue in Java 8

    In this post, we will see about Java 8 PriorityQueue. When the objects are supposed to be processed on the basis of their priority, in that scenario we use PriorityQueue. It’s a special type of queue (also, unbound queues) where the elements can be ordered either as per their natural ordering or based on a […]

  • 06 October

    2d Arraylist java example

    In this post, we will see how to create 2d Arraylist in java. Best way to create 2d Arraylist is to create list of list in java. [crayon-607a6ec46928a604088284/] Let’s create a program to implement 2d Arraylist java. [crayon-607a6ec4692a2214758786/] Output: 2nd element in list3 : List3_Str2 3nd element in list1 : List1_Str3 1st element in list2 […]

  • 21 October

    How to Sort HashSet in Java

    In this post, we will see how to sort HashSet in java. HashSet is a collection which does not store elements in any order. You might come across a situation where you need to sort HashSet. There can be many ways to sort HashSet, we will see two methods here. Using TreeSet You can use […]

  • 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 this method. [crayon-607a6ec469615516601256/] Output [John, Martin, Mary] 2. Using HashSet constructor() We can directly call HashSet‘s constructor for java set […]

  • 10 August

    Java Set to Array

    In this post, we will learn java set to array conversion. There are many ways to convert set to an array. 1. Using Java 8’s Stream If you are using Java 8, I would recommend using this method. [crayon-607a6ec4697f8980033174/] Output [John, Martin, Mary] 2. Using toArray() We can directly call toArray method on set object […]

  • 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-607a6ec469a07139383604/] 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-607a6ec469bff808697183/] Example : Let’s see both the function with the help of example. [crayon-607a6ec469c04158544429/] 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 […]