Iterator Applets in Java

Source: Internet
Author: User

 

 Import  Java. util. collection;  Import  Java. util. hashset;  Import  Java. util. iterator;  Public   Class  Testiterator {  Public   Static   Void  Main (string [] ARGs) {collection books = New Hashset (); books. Add ( "Java handouts" ); Books. Add ( "Java Ajax" ); Books. Add ( "Java authoritative guide" );  //  Get the iterator corresponding to the books set Iterator it = Books. iterator ();  While (It. hasnext ()){ //  The data type returned by it. hasnext () is object, so forced type conversion is required. String book = (String) it. Next (); system. Out. println (book ); If (Books. Equals ("Java handout" ) {It. Remove ();}  //  Copying a book does not change the book itself. Book = "test string" ;} System. Out. println (books );}}
 Import  Java. util. collection;  Import  Java. util. hashset;  Import  Java. util. iterator;  Public   Class Testiterator {  Public   Static   Void  Main (string [] ARGs) {collection books = New  Hashset (); books. Add ( "Java handouts" ); Books. Add ( "Java Ajax" ); Books. Add ( "Java authoritative guide" );  //  Get the iterator corresponding to the books set Iterator it = Books. iterator (); While (It. hasnext ()){ //  The data type returned by it. hasnext () is object, so forced type conversion is required. String book = (String) it. Next (); system. Out. println (book );  If (Book. Equals ("Java handout" )){  //  The Set elements cannot be modified during iterator iteration.CodeException thrown  Books. Remove (book );}}  // System. Out. println (books );  }} 
 
 

 

 
 

Java Ajax
Java Handouts
Java authoritative guide
[Java Ajax, Java handouts, Java authoritative guide]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.