• 17 May

    How to Initialize an Array with 0 in Java

    This article discusses the arrays and different ways to initialize an array with 0 in Java. Arrays The arrays are the fundamental data structures, they are sequences of elements stored in contiguous memory locations. The first step when using a data structure involves initializing the data structure which in our case is arrays. Array instantiation […]

  • Set an array to another array in java
    23 April

    Set an Array Equal to Another Array in Java

    This article discusses methods to set an array equal to another array in Java. Arrays are the most basic data structures that store the data at contiguous memory locations. The operations on the array elements are performed using the indices. Setting an Array Variable Equal to Another Array Variable It might seem logical to set […]

  • Check if array is empty in Java
    04 March

    Check if Array Is Empty in Java

    In this post, we will see how to check if array is empty in Java. The arrays are a data structure that facilitates storing multiple instances of data together in contiguous memory locations. This article discusses different cases when an array is considered to be empty in Java. It also discusses methods to check, for […]

  • Initialize empty array in java
    01 January

    Initialize empty array in java

    💡 Outline You can use below code to initialize empty array in java. [crayon-62c2204099986060614901/] Introduction In this post, we take a look on How to Initialize empty array in Java. We will look at different ways to Initialize arrays in Java with dummy values or with prompted user inputs. Arrays in Java follow a different […]

  • Write a Program to Find the Maximum Difference between Two Adjacent Numbers in an Array of Positive Integers
    07 April

    Write a Program to Find the Maximum Difference between Two Adjacent Numbers in an Array of Positive Integers

    In this article, we look at a problem : Given an Array of Positive Integers, Find the [Maximum Difference](https://java2blog.com/maximum-difference-between-two-elements-in-array/ "Maximum Difference") between Two Adjacent Numbers. For each pair of elements we need to compute their difference and find the Maximum value of all the differences in array. Let us look at an example, Consider this […]

  • 11 November

    How to print array in java

    Learn about how to print array in java in multiple ways.

  • 09 October

    Initialize 2D array in Java

    In this article, we will learn to initialize 2D array in Java. The array is a data structure that is used to collect a similar type of data into contiguous memory space. An array can be a single-dimensional or multidimensional. An array that has 2 dimensions is called 2D or two-dimensional array. There are several […]

  • 24 October

    Java add to array

    In this post, we will see how to add elements to the array. Using Apache’s common lang library You can use varargs add method to add elements to array dynamically. Here are the few add overloaded methods provided by ArrayUtils class If you want to add more than one element, you can use ArrayUtils’s addAll […]

  • 10 November

    Java Convert Array to List

    In this post, we will see how to convert array to list in java. There are may ways to convert array to list: By using Arrays.asList(): This is an easy method to convert Array into list.We just need to pass array as parameter to asList() method.It is a Static method available in Arrays class so, […]