Results 1 to 3 of 3
- 12-09-2010, 05:54 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 45
- Rep Power
- 0
Iterators - can you assign new values to them?
I know an Iterator object has the hasNext(), next(), and remove() methods, but is there a way to assign a different value to an Iterator object as you iterate through? For instance:
What would be the code to replace the comment line in the preceding code without having to use the set() method of the Vector object itself on the v vector? Thanks for your help!Java Code:Vector v = new Vector(); v.add(1); v.add(2); v.add(3); for (Iterator i = v.iterator; i.hasNext(); ) { // set current i value to its value times 10 }
-Derek Raimann
- 12-09-2010, 06:25 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
you could use the ListIterator!
Java Code:for (ListIterator<Integer> i = v.listIterator(); i.hasNext(); ) { i.set(i.next()*10); }
- 12-09-2010, 07:11 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 45
- Rep Power
- 0
Similar Threads
-
Assign Different Objects to Array
By Briksins in forum New To JavaReplies: 17Last Post: 12-08-2010, 09:44 AM -
Iterator over Iterators
By chawlakunal in forum New To JavaReplies: 2Last Post: 05-22-2010, 09:16 PM -
Assign it, or call it again,, (again!)
By sonny in forum New To JavaReplies: 4Last Post: 03-17-2010, 02:47 AM -
Array Assign Values from a Textfile
By fawadafr in forum Java AppletsReplies: 6Last Post: 11-30-2008, 12:10 AM -
Assign a keyboard key to a JButton.
By gszauer in forum AWT / SwingReplies: 1Last Post: 12-15-2007, 10:42 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks