I have been coding in Android a lot lately, although I am comfortable in JAVA, but I lack some ideas about the basic concepts that are used there.
I am interested to know if there is a difference between the two codes.
First method:
ArrayList <String> myList = new ArrayList <String>();
and using String temp = myList.get(1);
Second method:
ArrayList myList = new ArrayList(); //Specified as member variable.
and using
String temp1 = myList.get(1).toString();
I know him about casting. The first method has a big advantage over the second, Most of the time in real coding I have to use the second method, because the arraylist can take different types of data, I end up pointing
ArrayList <Object> = new ArrayList <Object>();
or more general way.
source
share