• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java 1.5 typed collections...

 
Tad Dicks
Ranch Hand
Posts: 264
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I make the following declaration:



then later do the following


Is that legal? does the iterator automatically return an object of the type specified in the angle brackets? if not is this just an oversight or was there a compelling reason for not typing the iterator to what was specified in the collection/list? It seems that its necessary to cast the object coming out of the iterator...

or should I be saying for(Iterator<String> = list.iterator....??

-Tad
 
Tad Dicks
Ranch Hand
Posts: 264
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I guess I just need to ask the question out loud(er type it out) to figure it out... heh.
 
Rick O'Shay
Ranch Hand
Posts: 531
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You got it.

Side note. Rather than this:

ArrayList<String> list = new ArrayList<String>()

Do this:

List<String> list = new ArrayList<String>()

And this:

for(String string : list)
{
...
}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic