Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Difference of outputs of print of int[] ,String[] and char[] in Java

My question is simple .I know output but i can’t know why is different outputs of all of them.

Firstly, i wanted to get output of array what is created newly and is empty .i coded like that:

(https://i.stack.imgur.com/V40Jw.png)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

and i got output like that:

(https://i.stack.imgur.com/6cJdU.png)

I hope you will take into account that I am just learning Java 1 month

>Solution :

Here you have created an array of integers with a length of 2 using new int[2]. In Java, when you initialize an array of integers using new int[2], it initializes each element to its default value, which is 0 for int type.
Same goes for arrays of char and string and as well you have not intitialized any of the arrays that is why you are getting their respective default values as output .

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading