

{"id":6957,"date":"2018-02-01T11:51:14","date_gmt":"2018-02-01T11:51:14","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=6957"},"modified":"2026-05-07T16:48:46","modified_gmt":"2026-05-07T11:18:46","slug":"java-array","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/java-array\/","title":{"rendered":"Java Array Tutorial &#8211; Declare, Create, Initialize, Clone with Examples"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:2044,&quot;href&quot;:&quot;http:\\\/\\\/csc.columbusstate.edu\\\/woolbright\\\/java\\\/equals.html&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20210619222525\\\/http:\\\/\\\/csc.columbusstate.edu\\\/woolbright\\\/java\\\/equals.html&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-10 23:40:37&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2025-12-26 12:57:32&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-27 06:52:22&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-18 10:59:53&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-07 02:48:07&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-06 14:22:39&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-11 11:16:45&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-19 05:46:32&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-06 12:09:44&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-02 11:22:06&quot;,&quot;http_code&quot;:404}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-02 11:22:06&quot;,&quot;http_code&quot;:404},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>In order to understand the concept of arrays, you have to understand the real-life situation of the need for arrays.<\/p>\n<p>Your birthday is coming up and you have a room full of your classmates to treat to chocolates. All they are surviving college\/school with you. But you remember that you have 70 of your classmates. But, you can barely hold around 10 chocolates with both of your hands. The maximum that you can carry around is 7. So do you do round trips from your school\/college to the shop till all of your friends get 1 chocolate each? No!<\/p>\n<p>You decide to get one big plastic jar and put all the chocolates inside it. That way it is easier to carry all the chocolates and lower risk of spilling!<\/p>\n<p>Brilliant! Arrays in Java are for the exact same purpose! Let us dive in.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Arrays-in-java-df.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79065\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Arrays-in-java-df.jpg\" alt=\"Arrays in java\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Arrays-in-java-df.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Arrays-in-java-df-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Arrays-in-java-df-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Arrays-in-java-df-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Arrays-in-java-df-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Arrays-in-java-df-520x272.jpg 520w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/p>\n<h3>Arrays in Java<\/h3>\n<p>Arrays are a collection of data items that have the same data type and are referred to by a common name. Each array element is stored in such a way that each element can be calculated by applying a mathematical formula to its index. For example, an Integer array will have all integer elements, and a String array will have Strings for each element of the array.<br \/>\nThe elements are stored in a contiguous memory location, which means all the memory elements are stored one after another.<\/p>\n<p><strong>However, some points set the arrays in Java apart from other languages:<\/strong><\/p>\n<ul>\n<li>All arrays in Java are dynamically allocated.<\/li>\n<li>In Java, the length of the array is calculated using .length.This might seem to be similar to the length() method of strings. However, the concept is that the length is a final variable which puts the length of arrays. This is, however, not applicable for strings as the string has a length() method to calculate the length of the string. An array in Java is declared similarly like other variables. The only difference is that a [] is added at the end of the declaration.<\/li>\n<li>The size of the array must be an integer value and not short, nor long.<\/li>\n<li>The variables inside the array start from index 0.<\/li>\n<li>Java can also be implemented as a parameter in methods, local &amp; static variables.<\/li>\n<li>The superclass of arrays is an Object.<\/li>\n<li>The interfaces Cloneable and Serializable are implemented by arrays.<\/li>\n<li>When the arrays contain primitive datatypes, they are stored in memory locations that are contiguous. However, when arrays of objects are created, they are stored in heap memory.<\/li>\n<\/ul>\n<p>Arrays always have indexes. These indices typically denote the position of each element in the array. Since the elements are in the contiguous format, the indexing is done from 0(the first element) till n-1 where n is the length of the array. For example, an array of length 5 would have indices ranging from 0 to 4 (5-1).<\/p>\n<h3>Need for Java Arrays<\/h3>\n<p>In today\u2019s world, memory is a very expensive resource, and quality usage of memory saves a lot of money and effort. Hence, in programming, when we have to store a lot of data having similar data types, we can use arrays. For example, if we have to store a hundred variables each of type integer, then instead of writing \u201cint a,b,c\u2026\u2026..\u201d, we can declare an array of size 100 and type int.<\/p>\n<p>This way, we do not have to assign a different name to all the variables, and each of them can be individually accessed by their index in the array. We can simply get the 87th integer by arr[87], where arr is the name of the array.<\/p>\n<h3>Array Applications in Java<\/h3>\n<p>Arrays are a fundamental data structure in Java and have a wide range of applications. They are commonly used to store collections of similar data items, such as lists of numbers, names, or objects. Here are some specific examples of how arrays are used in Java programming:<\/p>\n<ul>\n<li><strong>Storing sensor data:<\/strong> In an Internet of Things (IoT) application, sensor data like temperature readings or light levels might be stored in an array for processing and analysis.<\/li>\n<li><strong>Image processing:<\/strong> When working with digital images, arrays can be used to represent the pixel data of the image. Each element in the array corresponds to a single pixel, storing its color information.<\/li>\n<li><strong>Developing games:<\/strong> In game development, arrays can be used to store game data like character stats, level maps, or animation sequences. By effectively using arrays, programmers can create dynamic and interactive game experiences.<\/li>\n<\/ul>\n<h3>Java ArraysIndexOutOfBoundsException<\/h3>\n<p>A common mistake of all programmers while using arrays is that they try to access indexes that are outside the limit. For example, if an array is of length 6, then the program can use any index of the array between 0 and 5. But sometimes the program tries to access elements outside this range. That is when the compiler throws an ArrayIndexOutOfBoundsException error.<\/p>\n<p><strong>Java program to illustrate the ArrayIndexOutOfBoundsException:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.arrayclass;\r\nclass ExceptionArrayIndex {\r\n  public static void main(String[] args) {\r\n    int arr[] = new int[] {\r\n      1,\r\n      2,\r\n      3,\r\n      4,\r\n      5\r\n    };\r\n    int j;\r\n    for (j = 0; j &lt;= arr.length; j++) {\r\n      System.out.println(arr[j]);\r\n    }\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">1<br \/>\n2<br \/>\n3<br \/>\n4<br \/>\n5<\/div>\n<div class=\"code-output\">Exception in thread &#8220;main&#8221; java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5<\/div>\n<h3>Declaration of Java Arrays<\/h3>\n<p>Arrays are declared in a simple manner. It includes the type of the variable followed by the variable name and closed box brackets([]).<br \/>\nThe syntax is as follows:<\/p>\n<p><strong>type var_name []<\/strong><br \/>\n<strong>or<\/strong><br \/>\n<strong>type[] var_name;<\/strong><\/p>\n<p>However, writing this code alone does not allocate memory to the array. It simply informs the compiler that the array exists. In order to allow memory to the array, you need to instantiate it as we did with objects, by using the new keyword.<\/p>\n<p><strong>Then the syntax becomes:<\/strong><\/p>\n<p><strong>type var_name [] = new type [size_of_array];<\/strong><\/p>\n<p>Here, type is the data type of the array to be declared, and the size of the array is mentioned within the square brackets.<br \/>\nAs soon as you declare the array, all the elements within the array will be stored as the default values for that particular datatype. For example, if you declare an integer array, all the elements within the array will automatically be set to 0, which is the default value of the datatype.<br \/>\nHowever, if the datatype is a reference datatype, then the values would be set to null.<\/p>\n<p>This process of allocation of memory to the array in Java renders all the arrays <strong>dynamically allocated.<\/strong><\/p>\n<p>Java elements can be accessed both by a for loop and a for each loop. However, the elements in the array cannot be altered by using the for each loop.<\/p>\n<h3>Java Arrays can be declared by using literals<\/h3>\n<p>If all the elements of an array are known previously, then the elements can be added to an array literal<\/p>\n<p><strong>The syntax for using the array literal declaration is:<\/strong><\/p>\n<p>datatype &lt;var_name&gt;[] = new datatype[] {element1,element2,element3\u2026.element n};<\/p>\n<h3>Java for-each loop to iterate over arrays<\/h3>\n<p>Just like the for loop, the for-each loop can also be used to iterate over arrays. The elements of the loop cannot be altered when accessed by a for-each loop.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">for ( &lt; datatype &gt; &lt;variable &gt; :&lt;collection &gt; ) {\r\n  \/\/code to be executed\r\n}<\/pre>\n<p><strong>Java program to illustrate the use of the for-each loop:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.arrayclass;\r\nclass ForEachArray {\r\n  public static void main(String[] args) {\r\n    int arr[] = new int[] {\r\n      1,\r\n      2,\r\n      3,\r\n      4,\r\n      5\r\n    };\r\n    for (int i: arr) {\r\n      System.out.println(i);\r\n    }\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">1<br \/>\n2<br \/>\n3<br \/>\n4<br \/>\n5<\/div>\n<p><strong>Java program to illustrate the use of arrays in a program:\u00a0<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.arrayclass;\r\npublic class BasicArray {\r\n  public static void main(String[] args) {\r\n    System.out.println(\"This program illustrates declaration and use of java arrays\");\r\n    int i;\r\n\r\n    \/\/Declaring array literal\r\n    int arr_lit[] = new int[] {\r\n      69,\r\n      666,\r\n      420,\r\n      117\r\n    };\r\n\r\n    \/\/Declaring array object\r\n    int arr_obj[] = new int[6];\r\n\r\n    \/\/Using for loop to access elements in arr_obj\r\n    for (i = 0; i &lt; 6; i++) {\r\n      arr_obj[i] = i;\r\n    }\r\n\r\n    \/\/using for each loop to iterate through arr_lit\r\n    System.out.println(\"The array literal has values\");\r\n    for (int j: arr_lit) {\r\n      System.out.print(j + \" \");\r\n    }\r\n    System.out.println(\"\");\r\n    \/\/using for loop to iterate over each element in arr_obj\r\n\r\n    System.out.println(\"The array object has values:-\");\r\n    for (i = 0; i &lt; 6; i++) {\r\n      System.out.print(arr_obj[i] + \" \");\r\n    }\r\n\r\n    \/\/we go from 0 to the number before the length of the array\r\n    \/\/because arrays are indexed from 0 to n-1\r\n    \/\/n is the size of the array\r\n\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">This program illustrates the declaration and use of java arrays<br \/>\nThe array literal has values<br \/>\n69 666 420 117<br \/>\nThe array object has values:-<br \/>\n0 1 2 3 4 5<\/div>\n<h3>Memory representation of single-dimensional arrays in Java<\/h3>\n<p>As soon as the compiler executes the code int a[] = new int[5]; First, it creates a reference variable named \u2018a\u2019. This variable points to the data that is stored in the array. The data items are contiguous, and they are indexed from 0 to (length of the array -1). In this case, it is from 0 to 4.<\/p>\n<p><strong>A pictorial representation of an array in memory:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Pictorial-representation-of-an-array-in-memory.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79066\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Pictorial-representation-of-an-array-in-memory.jpg\" alt=\"java array\" width=\"476\" height=\"414\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Pictorial-representation-of-an-array-in-memory.jpg 476w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Pictorial-representation-of-an-array-in-memory-300x261.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Pictorial-representation-of-an-array-in-memory-150x130.jpg 150w\" sizes=\"auto, (max-width: 476px) 100vw, 476px\" \/><\/a><\/p>\n<h3>Java Anonymous Arrays<\/h3>\n<p>While passing an array to a method, you need not set a name for the array. These arrays with no names are called anonymous arrays. They can simply be passed from the function call to the method.<\/p>\n<p><strong>Java program to illustrate the concept of anonymous arrays:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.arrayclass;\r\nclass AnonymousArray {\r\n  static void printArray(int arr[]) {\r\n    for (int i: arr) {\r\n      System.out.println(i);\r\n    }\r\n  }\r\n  public static void main(String[] args) {\r\n    printArray(new int[] {\r\n      1,\r\n      2,\r\n      3,\r\n      4,\r\n      5,\r\n      0\r\n    });\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">1<br \/>\n2<br \/>\n3<br \/>\n4<br \/>\n5<br \/>\n0<\/div>\n<h3>Java Array members<\/h3>\n<p>Arrays are objects in a class, and the Array class is a direct subclass of the class Object. Hence, every member of the array object has to follow these conditions:<\/p>\n<p>a. The final variable length of the array must have either a positive value or zero.<br \/>\nb. Every member inherits all the methods of the Object class except the clone method.<br \/>\nc. This clone method overrides the method in the Object class and does not throw any checked exceptions.<\/p>\n<h3>Array of Objects in Java<\/h3>\n<p>Remember the example we took while starting the chapter about your birthday, and you carrying a box of chocolates instead of carrying each one of them by hand? Well, consider candy as a class. Now this candy has many different objects, such as lollipops with various flavors<br \/>\nsuch as chocolate or vanilla.<\/p>\n<p>Hence, all these, instead of having individual objects of their own, can be presented as an array of objects of type candy.<\/p>\n<p><strong>The syntax is the same for declaring an array of objects:<\/strong><br \/>\n&lt;datatype&gt; var_name[] = new &lt;datatype&gt;[size];<\/p>\n<p><strong>Java program to illustrate the array of objects:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.arrayclass;\r\npublic class Candy {\r\n\r\n  \/\/class to define candy. \r\n  public String candy_name;\r\n  public String flavour;\r\n\r\n  Candy(String cname, String flav) {\r\n    candy_name = cname;\r\n    flavour = flav;\r\n  }\r\n\r\n  public static void main(String[] args) {\r\n    int i;\r\n    Candy arr_obj[] = new Candy[5];\r\n    \/\/created five objects of candy\r\n\r\n    arr_obj[0] = new Candy(\"Alpenliebe\", \"Vanilla\");\r\n    arr_obj[1] = new Candy(\"Alpenliebe\", \"Butterscotch\");\r\n    arr_obj[2] = new Candy(\"Eclairs\", \"Chocolate\");\r\n    arr_obj[3] = new Candy(\"Mars\", \"Chocolate\");\r\n    arr_obj[4] = new Candy(\"Snickers\", \"Chocolate\");\r\n\r\n    \/\/declared objects in the array candy \r\n\r\n    for (i = 0; i &lt; 5; i++) {\r\n      System.out.println(arr_obj[i].candy_name + \" has a flavor of \" + arr_obj[i].flavour);\r\n\r\n    }\r\n\r\n  }\r\n\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Alpenliebe has a flavor of Vanilla<br \/>\nAlpenliebe has a flavor of Butterscotch<br \/>\nEclairs has a flavor of Chocolate<br \/>\nMars has a flavor of Chocolate<br \/>\nSnickers has a flavor of Chocolate<\/div>\n<h3>Multidimensional Arrays in Java<\/h3>\n<p>Arrays are not limited to one dimension only. Multidimensional arrays exist and are used in mathematical calculations, too. These are created by each element of one array holding a reference to another array.<\/p>\n<p>Two-dimensional arrays are very popular in programming. However, the JVM limits the maximum number of dimensions to be created to 255.<\/p>\n<p><strong>Syntax of multidimensional arrays in Java:<\/strong><\/p>\n<p>&lt;datatype&gt;[][]&lt;var_name&gt;= new &lt;datatype&gt;[size1][size2];<br \/>\nor<br \/>\n&lt;datatype&gt;&lt;var_name&gt;[][]= new &lt;datatype&gt;[size1][size2];<br \/>\nor<br \/>\n&lt;datatype&gt;[]&lt;var_name&gt;[]= new &lt;datatype&gt;[size1][size2];<\/p>\n<p><strong>Java program to illustrate the usage of multidimensional arrays:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.arrayclass;\r\npublic class DoubleDimArray {\r\n  public static void main(String[] args) {\r\n    \/\/Using multidimensional array literal\r\n    int arr_lit[][] = {\r\n      {\r\n        1,\r\n        2,\r\n        3\r\n      },\r\n      {\r\n        4,\r\n        5,\r\n        6\r\n      },\r\n      {\r\n        7,\r\n        8,\r\n        9\r\n      }\r\n    };\r\n\r\n    \/\/using multidimensional array object\r\n    int val = 1;\r\n\r\n    int matrix[][] = new int[4][4];\r\n\r\n    for (int i = 0; i &lt; 4; i++) {\r\n      for (int j = 0; j &lt; 4; j++) {\r\n        matrix[i][j] = val;\r\n        val++;\r\n      }\r\n    }\r\n    \/\/printing the matrix\r\n    System.out.println(\"The matrix is\");\r\n    for (int i = 0; i &lt; 4; i++) {\r\n      for (int j = 0; j &lt; 4; j++) {\r\n        System.out.print(matrix[i][j] + \"\\t\");\r\n\r\n      }\r\n      \/\/adding a blank line after every row\r\n      System.out.println(\"\");\r\n    }\r\n  }\r\n\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">The matrix is<br \/>\n1 2 3 4<br \/>\n5 6 7 8<br \/>\n9 10 11 12<br \/>\n13 14 15 16<\/div>\n<p>The tab escape sequence is added for clear output.<\/p>\n<h3>Cloning Arrays in Java<\/h3>\n<p>Cloning is an intricate concept in Java. As the name suggests, the cloning of an array is the process of creating another array with the same values. However, the process of cloning is different for single-dimensional and multidimensional arrays.<\/p>\n<h4>1. Java Single-Dimensional Array Cloning<\/h4>\n<p>When a single-dimensional array is cloned, every element is copied from the original array. Note that all the elements are copied, and the references are not the same. This means that the members of the array that are cloned are the same in value, but their references are different. This is known as a <strong>deep copy.<\/strong><\/p>\n<h4>2. Java Multidimensional Array Cloning<\/h4>\n<p>Multidimensional arrays are arrays that contain arrays. Simply speaking, each element in a multidimensional array is a reference to a different array. While cloning, a new array is created with the array elements, but the subarrays are shared through references.<\/p>\n<p>While cloning multidimensional arrays, only a single array is created, and all the sub-arrays in it are referenced. This is known as a shallow<strong>\u00a0copy.<\/strong><\/p>\n<p><strong>Syntax of multidimensional array cloning:<\/strong><br \/>\n&lt;array2&gt; = &lt;array1&gt;.clone();<\/p>\n<p><strong>Java program to illustrate the concept of cloning:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.arrayclass;\r\nclass CloningArrays {\r\n\r\n  public static void main(String[] args) {\r\n    int newarr[] = new int[] {\r\n      1,\r\n      2,\r\n      3,\r\n      4,\r\n      5\r\n    };\r\n    int clonearr[] = newarr.clone();\r\n    for (int i: clonearr) {\r\n      System.out.println(i);\r\n    }\r\n    System.out.println(\"Check if references are equal\");\r\n    System.out.println(clonearr == newarr);\r\n\r\n    \/\/cloning multidimensional arrays\r\n    int multnew[][] = new int[][] {\r\n      {\r\n        1,\r\n        2,\r\n        3\r\n      },\r\n      {\r\n        4,\r\n        5,\r\n        6\r\n      },\r\n      {\r\n        7,\r\n        8,\r\n        9\r\n      }\r\n    };\r\n    int clonemult[][] = multnew.clone();\r\n    for (int i = 0; i &lt; 3; i++) {\r\n      for (int j = 0; j &lt; 3; j++) {\r\n        System.out.print(clonemult[i][j] + \" \");\r\n      }\r\n      System.out.println(\"\");\r\n    }\r\n    System.out.println(\"Check if references to the outer array are the same. \");\r\n    System.out.println(multnew == clonemult);\r\n    System.out.println(\"Check if references of the inner array are the same. \");\r\n    System.out.println(multnew[0] == clonemult[0]);\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">1<br \/>\n2<br \/>\n3<br \/>\n4<br \/>\n5<br \/>\nCheck if references are equal<br \/>\nfalse<br \/>\n1 2 3<br \/>\n4 5 6<br \/>\n7 8 9<br \/>\nCheck if references to the outer array are the same.<br \/>\nfalse<br \/>\nCheck if references of the inner array are the same.<br \/>\ntrue<\/div>\n<h3>Passing arrays to a method<\/h3>\n<p>Arrays can be passed to a method. This enables the method to access and perform operations on the array. Various algorithms can be applied to the array once a particular method can access it.<\/p>\n<p><strong>Syntax for passing arrays to a method:<\/strong><br \/>\nmethod_name(name_of_array)<\/p>\n<h3>Returning arrays from a method<\/h3>\n<p>Similar to passing arrays to a function, arrays can also be returned to the calling statement of the method. This enables the method to perform operations on the array and return it.<\/p>\n<p><strong>The syntax for returning arrays from the method:<\/strong><br \/>\nreturn arr_name;<\/p>\n<p><strong>Java program to illustrate the passing and returning of arrays from methods:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.arrayclass;\r\npublic class PassReturnArrayToMethod {\r\n  static int[] increment1(int arr[]) {\r\n    int i;\r\n    for (i = 0; i &lt; arr.length; i++) {\r\n      arr[i] = arr[i] + 1;\r\n    }\r\n    return arr; \/\/returning array from method. \r\n  }\r\n  public static void main(String[] args) {\r\n    int orgarray[] = new int[] {\r\n      1,\r\n      2,\r\n      3,\r\n      4,\r\n      5\r\n    }; \/\/original array\r\n    int retarray[] = increment1(orgarray); \/\/passing array to method\r\n    System.out.println(\"The array when incremented by 1 becomes: \");\r\n    for (int i: retarray) {\r\n      System.out.print(i + \" \");\r\n    }\r\n\r\n  }\r\n\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">The array when incremented by 1 becomes:<br \/>\n2 3 4 5 6<\/div>\n<h3>Array class in Java<\/h3>\n<p>The array class in Java is particularly useful for performing functions that are tedious to write manually. It has a lot of methods for creating and accessing Java arrays. It also includes sorting, searching, and a lot of popular functions that are frequently useful by programmers to manipulate arrays.<\/p>\n<p>This is a part of the java.util package. This class inherits from the Object class.<\/p>\n<p><strong>Some of the useful methods are as follows:<\/strong><\/p>\n<h4>1. Java toString<\/h4>\n<p>This method converts the array to a string, which can then be easily printed without using for loops. This converts the array to string form, by separating each of its elements with a comma and enclosing the array within square brackets. It enables the programmer to print the array without having to use loops.<\/p>\n<p><strong>The syntax of Java toString is:<\/strong><br \/>\nArrays.toString(&lt;array&gt;);<\/p>\n<p><strong>Java program to illustrate the use of the toString method:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.arrayclass;\r\nimport java.util.Arrays;\r\nclass ToStringMethod {\r\n\r\n  public static void main(String[] args) {\r\n    int newarr[] = new int[] {\r\n      1,\r\n      2,\r\n      3,\r\n      4,\r\n      5\r\n    };\r\n    System.out.println(\"The array, when passed to the toString method, is: \" + Arrays.toString(newarr));\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">The array, when passed to the toString method, is: [1, 2, 3, 4, 5]<\/div>\n<h4>2. Java Binary Search<\/h4>\n<p>As the name suggests, the method implements a binary search algorithm and returns the index of the value that is to be searched. If the value is not found, it returns (-(insertion point)-1). The insertion point is the point where the element has to be inserted in the array.<\/p>\n<p><strong>The syntax of binary search in Java is:<\/strong><br \/>\nbinarySearch(&lt;array&gt;,&lt;element&gt;);<\/p>\n<p><strong>Java program to illustrate the use of the binarySearch method:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.arrayclass;\r\nimport java.util.Arrays;\r\nclass BinarySearchMethod {\r\n\r\n  public static void main(String[] args) {\r\n    int newarr[] = new int[] {\r\n      1,\r\n      2,\r\n      3,\r\n      4,\r\n      5\r\n    };\r\n    int search = 3;\r\n    System.out.println(\"The array, when passed to the binarySearch method, is: \" + Arrays.binarySearch(newarr, search));\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">The array, when passed to the binarySearch method, is: 2<\/div>\n<h4>3. Java Compare<\/h4>\n<p>This method simply compares the two arrays passed in its arguments lexicographically. This returns 0 if the arrays are the same.<\/p>\n<p><strong>The syntax of Java compare is:<\/strong><br \/>\nArrays.compare(array1,array2)<\/p>\n<p><strong>Java program to illustrate the use of the compare method:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import java.util.Arrays;\r\nclass CompareMethod {\r\n\r\n  public static void main(String[] args) {\r\n    int newarr[] = new int[] {\r\n      1,\r\n      2,\r\n      3,\r\n      4,\r\n      5\r\n    };\r\n    int newarr2[] = new int[] {\r\n      1,\r\n      2,\r\n      3,\r\n      4,\r\n      5\r\n    };\r\n    int search = 0;\r\n    System.out.println(\"The array, when passed to the  compare method, is: \" + Arrays.compare(newarr, newarr2));\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">The array, when passed to the compare method, is: 0<\/div>\n<h4>4. Java Fill<\/h4>\n<p>The fill method, as the name suggests, fills each of the indexes of the array with the value passed to it.<\/p>\n<p><strong>The syntax of the Java Fill method is:<\/strong><br \/>\nfill(Array, value)<\/p>\n<p><strong>Java program to illustrate the use of the fill method:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.arrayclass;\r\nimport java.util.Arrays;\r\nclass FillMethod {\r\n\r\n  public static void main(String[] args) {\r\n    int newarr[] = new int[] {\r\n      1,\r\n      2,\r\n      3,\r\n      4,\r\n      5\r\n    };\r\n    Arrays.fill(newarr, 54);\r\n    System.out.println(\"The array, when passed to fill method, is: \" + Arrays.toString(newarr));\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">The array, when passed to fill method, is: [54, 54, 54, 54, 54]<\/div>\n<h4>5. Java equals<\/h4>\n<p><strong><a href=\"http:\/\/csc.columbusstate.edu\/woolbright\/java\/equals.html\" target=\"_blank\" rel=\"noopener\">Java equals<\/a> <\/strong>method returns true if both arrays that are to be compared are equal. If not, it returns false. However, the deepEquals method is useful to check whether multidimensional arrays are equal to one another(i.e., it returns true if the corresponding pairs of elements are equal, even in nested arrays of arbitrary depth)<\/p>\n<p><strong>The syntax of the Java equals method is:<\/strong><br \/>\nArrays.equals(Object Array1,Object Array2)<br \/>\nArrays.deepEqual(Object Array1,Object Array2)<\/p>\n<p><strong>Java program to illustrate the use of equals and deepEquals:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.arrayclass;\r\nimport java.util.Arrays;\r\nclass Equals {\r\n\r\n  public static void main(String[] args) {\r\n\r\n    Integer arr1[] = new Integer[] {\r\n      1,\r\n      2,\r\n      3,\r\n      4,\r\n      5\r\n    };\r\n    Integer arr2[] = new Integer[] {\r\n      1,\r\n      2,\r\n      3,\r\n      4,\r\n      5\r\n    };\r\n\r\n    System.out.println(\"Is arr1 and arr2 equal? \" + Arrays.equals(arr1, arr2));\r\n    System.out.println(\"Is arr1 and arr2 equal? \" + Arrays.deepEquals(arr1, arr2));\r\n\r\n    Integer mat1[][] = new Integer[][] {\r\n      {\r\n        1,\r\n        2,\r\n        3\r\n      },\r\n      {\r\n        4,\r\n        5,\r\n        6\r\n      },\r\n      {\r\n        7,\r\n        8,\r\n        9\r\n      }\r\n    };\r\n    Integer mat2[][] = new Integer[][] {\r\n      {\r\n        1,\r\n        2,\r\n        3\r\n      },\r\n      {\r\n        4,\r\n        5,\r\n        6\r\n      },\r\n      {\r\n        7,\r\n        8,\r\n        9\r\n      }\r\n    };\r\n    System.out.println(\"Is mat1 and mat2 equal? \" + Arrays.equals(mat1, mat2));\r\n    System.out.println(\"Is mat1 and mat2 equal? \" + Arrays.deepEquals(mat1, mat2));\r\n\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Is arr1 and arr2 equal? true<br \/>\nIs arr1 and arr2 equal? true<br \/>\nIs mat1 and mat2 equal? false<br \/>\nIs mat1 and mat2 equal? true<\/div>\n<p>Notice that the equal method doesn&#8217;t think that matrices 1 and 2 are equal because it cannot check arrays of arbitrary depth.<\/p>\n<h4>6. Java Sort<\/h4>\n<p>The sort method, as the name suggests, sorts the array elements in ascending or descending order. This method does not return any value.<\/p>\n<p><strong>The syntax of the Java sort method is:<\/strong><br \/>\nArrays.sort(Array,startIndex,endIndex,Comparator);<\/p>\n<p><strong>Java program to illustrate the use of the sort method:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.arrayclass;\r\nimport java.util.Arrays;\r\nimport java.util.Collections;\r\nclass ArraySort {\r\n\r\n  public static void main(String[] args) {\r\n\r\n    Integer arr1[] = {\r\n      3,\r\n      2,\r\n      1,\r\n      4,\r\n      5\r\n    };\r\n    Integer arr2[] = {\r\n      6,\r\n      4,\r\n      32,\r\n      2,\r\n      1\r\n    };\r\n    Arrays.sort(arr1);\r\n    Arrays.sort(arr2, Collections.reverseOrder());\r\n    \/\/we are using Integer instead of int because Collections does not work with primitive datatypes.\r\n    System.out.println(\"The array arr1 in ascending order is \" + Arrays.toString(arr1));\r\n    System.out.println(\"The array arr2 in descending order is \" + Arrays.toString(arr2));\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">The array arr1 in ascending order is [1, 2, 3, 4, 5]<br \/>\nThe array arr2 in descending order is [32, 6, 4, 2, 1]<\/div>\n<h3>Advantages and Disadvantages of Arrays in Java<\/h3>\n<h4><strong>Advantages of Array in Java<\/strong><\/h4>\n<ul>\n<li><strong>Defined memory storage:<\/strong> the size of the array can be defined at the time of array creation.<\/li>\n<li><strong>Indexing:<\/strong> By using the index number, data can be easily fetched from a particular index.<\/li>\n<li>An array is useful when iterating over loops<\/li>\n<li><strong>Linear memory:<\/strong> The linear memory allocation of array items makes the array items easier to access.<\/li>\n<\/ul>\n<h4>Disadvantages of Array in Java<\/h4>\n<ul>\n<li>While creating an array, the size of the array defined can not be changed. During runtime, when more elements are required to add than the array size cannot be enlarged.<\/li>\n<li>In case of an array created of a larger size, but the elements used require less memory than the remaining space, then the memory that is not used does not get utilized efficiently.<\/li>\n<\/ul>\n<h3>Summary<\/h3>\n<p>We learned about a very important concept of Java in this article called arrays. Arrays are extremely useful in programming as it saves a lot of space. We also learned about some useful methods in the Java class Array.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In order to understand the concept of arrays, you have to understand the real-life situation of the need for arrays. Your birthday is coming up and you have a room full of your classmates&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":79065,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[2574,3141,3630,6717,7380,7381,7606,9221,9434,15017],"class_list":["post-6957","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-cloning-of-array","tag-creating-java-array","tag-declaration-of-array-in-java","tag-initializing-java-array","tag-java-array-accessing","tag-java-array-example","tag-java-multidimensional-array","tag-one-dimensional-array-in-java","tag-passing-array-to-method","tag-types-of-array-in-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java Array Tutorial - Declare, Create, Initialize, Clone with Examples - DataFlair<\/title>\n<meta name=\"description\" content=\"Java array tutorial helps you to declare &amp; instantiate an array. Learn how to access array elements using for loop and cloning of arrays.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/java-array\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Array Tutorial - Declare, Create, Initialize, Clone with Examples - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Java array tutorial helps you to declare &amp; instantiate an array. Learn how to access array elements using for loop and cloning of arrays.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/java-array\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-01T11:51:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-07T11:18:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Arrays-in-java-df.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Array Tutorial - Declare, Create, Initialize, Clone with Examples - DataFlair","description":"Java array tutorial helps you to declare & instantiate an array. Learn how to access array elements using for loop and cloning of arrays.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/java-array\/","og_locale":"en_US","og_type":"article","og_title":"Java Array Tutorial - Declare, Create, Initialize, Clone with Examples - DataFlair","og_description":"Java array tutorial helps you to declare & instantiate an array. Learn how to access array elements using for loop and cloning of arrays.","og_url":"https:\/\/data-flair.training\/blogs\/java-array\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-02-01T11:51:14+00:00","article_modified_time":"2026-05-07T11:18:46+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Arrays-in-java-df.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/java-array\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/java-array\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Java Array Tutorial &#8211; Declare, Create, Initialize, Clone with Examples","datePublished":"2018-02-01T11:51:14+00:00","dateModified":"2026-05-07T11:18:46+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/java-array\/"},"wordCount":2735,"commentCount":3,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/java-array\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Arrays-in-java-df.jpg","keywords":["Cloning of Array","creating java array","declaration of array in java","Initializing java array","java array Accessing","java array example","Java Multidimensional Array","One-Dimensional Array in java","Passing Array to Method","types of array in java"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/java-array\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/java-array\/","url":"https:\/\/data-flair.training\/blogs\/java-array\/","name":"Java Array Tutorial - Declare, Create, Initialize, Clone with Examples - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/java-array\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/java-array\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Arrays-in-java-df.jpg","datePublished":"2018-02-01T11:51:14+00:00","dateModified":"2026-05-07T11:18:46+00:00","description":"Java array tutorial helps you to declare & instantiate an array. Learn how to access array elements using for loop and cloning of arrays.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/java-array\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/java-array\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/java-array\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Arrays-in-java-df.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Arrays-in-java-df.jpg","width":1200,"height":628,"caption":"Arrays in java"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/java-array\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Java Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/java\/"},{"@type":"ListItem","position":3,"name":"Java Array Tutorial &#8211; Declare, Create, Initialize, Clone with Examples"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=6957"}],"version-history":[{"count":17,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6957\/revisions"}],"predecessor-version":[{"id":148264,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6957\/revisions\/148264"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/79065"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=6957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=6957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=6957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}