aspose file tools*
The moose likes Beginning Java and the fly likes remove method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "remove method?" Watch "remove method?" New topic
Author

remove method?

xallan
Greenhorn

Joined: Apr 23, 2001
Posts: 2
When removing an element in collection, we can use Collection interface's remove(Object) or get a Iterator from that collection, then use Iterator's remove() method. But
What��s the difference between these two method? Are there efficiency or security differences?
Thanks for any help.
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
xallan,
We get a surprizing number of users with similar names. That's why we have established and enforce a Naming Policy It can benifit you, read Book Giveaway Page
The main difference is if you have created an Iterator or not on the collection. If you havn't then the Iterators remove method isn't available to you. If you have and you use the Colections remove method, the next time you try and access the Iterator, you get an IllegalStateException. The Iterator now points to more elements then are in the Collection.

------------------
Hope This Helps
Carl Trusiak, SCJP2
[This message has been edited by Carl Trusiak (edited April 23, 2001).]


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Allan Wang
Greenhorn

Joined: Apr 23, 2001
Posts: 20
Thanks. I changed my username for winning a free book.
From your reply, I think the idea is I shouldn't mix two kinds of remove method. But another question: Which one is better in efficiency and security?
Best Regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: remove method?