Detailed JAVA Iterator code

Source: Internet
Author: User

Iterator interface 1. All the container classes that implement the Collection interface have an Iterator method to return an object that implements the Iterator interface. 2. the Iterator object is called an Iterator for convenient operations to traverse data in an object. The Iterator interface defines the following methods: boolen hasNext (); // determines whether there is an element object next () on the right of the cursor (); // return the element on the right of the cursor and move the cursor to the next position void remove (); // Delete the element on the left of the cursor [java] import java. util. arrayList; import java. util. iterator; import org. hibernate. session; import org. hibernate. sessionFactory; import org. hibernate. cfg. configuration; public class test1 {/*** Iterator interface ** 1. All the container classes that implement the Collection interface have an Iterator method to return an object that implements the Iterator interface ** 2. the Iterator object is called an Iterator for convenient operations to traverse data in the object ** 3. The Iterator interface defines the following methods: ** boolen hasNext (); // determines whether there is an element on the right of the cursor * object next (); // return the element on the right of the cursor and move the cursor to the next position * void remove (); // Delete the element on the left of the cursor */public static void main (String [] args) {// TODO Auto-generated method stub ArrayList s = new ArrayList (); s. add (1123); s. add (2344444); s. add ("sssss"); Iterator iterator = s. iterator (); while (iterator. hasNext () {System. out. println (iterator. next ());}}}

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.