aspose file tools*
The moose likes Beginning Java and the fly likes Why doesn't Collection Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why doesn Watch "Why doesn New topic
Author

Why doesn't Collection Interface "set" have a get method like List?

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192
Why does an Collection.List have an Iterator and a get() method
While a Collection.Set does only have an iterator?
Thanks for your answers.
Thomas
CODE]
class Collection_List_Test1{
public static void main(String[] args) {
ArrayList alst = new ArrayList();
alst.add("anna");
alst.add("anna"); //Dublette; add() liefert "false" und
//f�gt Dublette nicht zum Set hinzu!!
alst.add("soorya");
System.out.println("Number of Elements: "+alst.size());
// Iterator myIterator = alst.iterator();
// while (myIterator.hasNext() ) {
// System.out.println(myIterator.next());
// }
for(int i=0; i<alst.size(); i++)
System.out.println(alst.get(i));
}
}
[/CODE]
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
A List has a defined order. A Set does not, so set.get(i) is not a meaningful concept.
It would make sense to have a get(i) operation for SortedSet and TreeSet, but there isn't one.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
 
Don't get me started about those stupid light bulbs.
 
subject: Why doesn't Collection Interface "set" have a get method like List?
 
Similar Threads
Iterator methods for HashMap class
My Preparation snippets (Collections!)
Generics Doubt (Casting)
IOException while reading objects
Begginer problems with ArrayList