File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "remove method?" Watch "remove method?" New topic

remove method?


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

Joined: Jun 13, 2000
Posts: 3340
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

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:
subject: remove method?
It's not a secret anymore!