As normal how we declare a string array when we dont know the size i.e how much data should be inserted then i give as String str = null. After that i can perform all the operations. When i try to do the same with int that is int arr = null. I dont get compilation error, when i try to access its elements i am getting the java.nullpointer exception.
Any help would be greatly appreciated.
I'm not sure I understand. If you set something to null, then try to access it, of course you will get a null pointer exception. In your first example, with the String array, the same thing would happen.
You don't assign anything to exp itself. Nowhere are you calling "exp = X" where X is something other than null. That means that the array itself remains null, and there are no elements to access.
With the String you are doing just that and that's why that example is working and this one isn't.
The easiest solution is adding "exp = new int;" just before the loop.
Joined: May 29, 2008
Look at the code below. I am using this to solve given input separated by ",". I think i have used some extra code. i.e i guess there is some other short way to do this. If any one know please share with me.