I have very basic doubt related to ArrayList Collection class.Consider the following declaration :
ArrayList<Integer> a1 = new ArrayList<Integer>();
Now, I want to know why are we using wrapper class 'Integer' here and why we can't use primitive type 'int'.I assume the answer would be so that we can perform different operations like toString etc. on the object created and to pass reference.Please correct me if I am wrong anywhere.
I executed following code to check how to pass reference but its not working.I mean method modify() should change value at index 0 if we are passing reference.....right? Please let me know what's wrong in below code:
import java.util.*;
class ArrayvsLinkedList
{
public static void main(String args[])
{
int n = 1000000;
ArrayList<Integer> a1= new ArrayList<Integer>();
for(int i=1;i<=n;i++)
a1.add(i);
System.out.println("Before method called"+a1.get(0));
new ArrayvsLinkedList().modify(a1.get(0));
System.out.println("After method called"+a1.get(0));
}
void modify(Integer x)
{
x=x*5;
System.out.println("Inside method "+x);
}
}