aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes for each loop Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "for each loop" Watch "for each loop" New topic
Author

for each loop

Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324



In the above code due to Autoboxing, by default Integer objects are added to tree, then why in the for each loop I cannot declare and use Integer reference variable . All I can use above is Object and NOT Integer.


SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
yes because you use TreeSet without any generics so it can take anything not only integers, if you want to use the TreeSet only for Integers then you have to do it like this



Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
Thanks Omar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: for each loop
 
Similar Threads
TreeSet contains method doesn't work for me??????
ClassCastException
testtree.Book cannot be cast to java.lang.Comparable
TreeSet gotcha
Binary tree