• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Thomas Markl
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic