What is the output of the following array list code fragment?
ArrayList
This is Java
To show you what happens, I have written a very simple program
public class Test { public static void main(String args[]) { int Array[] = {}; System.out.println(Array[0]); } }
Actually, there's no error in the program. The program complies successfully
I understand everything of the code you wrote except: int Array[] = {}; what is the output then? what will this line print?
But there are no elements in the array. So, you would get ArrayIndexOutOfBoundsException
That is the 2nd option
int Array[] = {}; This is used to declare a array
Thanks a lot I understand and know how to println a text but don't understand this point you are explaining http://prntscr.com/5ftz1x
Now I got it, thanks
There is another process: int Array[] = new Array[2];
The code which I first wrote: int Array[] = {1, 2, 3, 4} This is called an auto array. Instead of creating a new array, you can use this
You're welcome
Join our real-time social learning platform and learn together with your friends!