Different ways to print an Array in Java

Many times you need to print elements of Array in java language, it can be done in many ways and we will discuss many of those.

We will also try to find out which one is simplest and easiest.

Print Array using default toString method:

As we know all classes have toString method, let's try using that.




Output is not very useful as it prints some random string as below:


Print array using our own Implementation

Now let us iterate over each element and print it as below:



Output is:


Using Arrays.toString()

Since JDK5, java has Arrays class which has many utility methods for Array, like Arrays.toString() method to print elements of Array:

This is the simplest and easiest way to print array in java, for this you need to import java.util.Arrays class.





Output is:


Arrays.toString is not much usefull when array is multidimensional i.e 2-Dimension or 3-Dimension, in such scenario output is as below



Out is as below:


to print multidimensional array use java.util.Arrays.deepToString() method as below:



Output will be as below:


How to find duplicate ids in Javascript

Today i was in need to find a script to find duplicate component IDs in HTML page,
so i have written below javascript script.



Hope this helps.