| Author |
Arraylist and for enchanced loop question
|
Dinesh Tahiliani
Ranch Hand
Joined: Aug 06, 2007
Posts: 486
|
|
Hello Ranchers,
have a doubt in above example.
I am using the for enchanced loop. Not understanding the thing that how come students(in this case is arraylist ) assign to Student(which is the class). Can anyone shed some lights on this please :?:
|
Thanks<br />Dinesh
|
 |
Prav sharma
Ranch Hand
Joined: Feb 07, 2005
Posts: 102
|
|
The arraylist is a just a data structure to hold the Student Objects.
Now can't you iterate through a data structure with a data type which is stored in that?
In your case "A student object"
Or alternatively think like this,
You are having a list of Students
Dinesh Tahiliani wrote:
Hello Ranchers,
have a doubt in above example.
I am using the for enchanced loop. Not understanding the thing that how come students(in this case is arraylist ) assign to Student(which is the class). Can anyone shed some lights on this please :?:
|
 |
Dinesh Tahiliani
Ranch Hand
Joined: Aug 06, 2007
Posts: 486
|
|
Didn't get you my friend. can you please expalin in simple terms with the example mentioned by me
:?:
|
 |
Prav sharma
Ranch Hand
Joined: Feb 07, 2005
Posts: 102
|
|
Ok.
In your code you have created a Arraylist of Students ( think as collection of students ).
With this statement you are saying that you need a arrylist which you'll be using to store Student objects
Arraylist<student> = new Arraylist <student>();
Now you are adding to it Student objects.
# students.add(a);
# students.add(b);
# students.add(c)
If you want to iterate through it then you have to retrieve the objects.
| Student a | Student b | Student c |
Now think , if you remove something from this list, then what will come out? Of course a Student Object.
Is it clear now?
Dinesh Tahiliani wrote:Didn't get you my friend. can you please expalin in simple terms with the example mentioned by me
:?:
|
 |
Punit Singh
Ranch Hand
Joined: Oct 16, 2008
Posts: 952
|
|
for each loop internally uses Iterator of ArrayList, you can assume something like this:
|
SCJP 6
|
 |
 |
|
|
subject: Arraylist and for enchanced loop question
|
|
|