Results 1 to 3 of 3
Thread: for..iterator
- 11-28-2010, 02:08 PM #1
for..iterator
Consider the following code snippet:
Does the for loop create a copy of the staff array in order to iterate through each staff member?employee[] staff = new Employee[100];
//assume a procedure that retrieves 100 names from a data source
retrieveEmployees(staff);
//cost cutting time...reduce salaries by 20 percent
for (employee e : staff)
reducesalaryBy20percent(staff);
:confused:
- 11-28-2010, 02:12 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
No it doesn't, it iterates over the original array. What is going wrong then? Also show us the definition of your reducesalaryBy20percent( ... ) method; you call it as if it takes an entire array of Employees but I guess it should just take a single Employee ...
kind regards,
JosLast edited by JosAH; 11-28-2010 at 02:14 PM.
When people rob a bank they get a penalty; when banks rob people they get a bonus.
-
The JLS states what the for-each loop does: JLS for-each
I don't see it making a copy of the iterable, but rather it extracts the value from each item in the iterable.
Similar Threads
-
Iterator as return and argument or Iterator-String(not visible in the test file)
By Aldarius in forum New To JavaReplies: 0Last Post: 05-18-2010, 12:53 AM -
Iterator help
By alpdog14 in forum New To JavaReplies: 2Last Post: 10-13-2009, 08:42 PM -
iterator method help..
By mayhewj7 in forum New To JavaReplies: 1Last Post: 04-08-2009, 03:45 AM -
iterator
By venkatallu in forum Advanced JavaReplies: 3Last Post: 09-23-2008, 01:32 PM -
Iterator
By eva in forum New To JavaReplies: 0Last Post: 01-31-2008, 02:07 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks