Collection Framework (collection store strings and traverse)

Source: Internet
Author: User

Collection case
Store strings and Traverse
Store custom objects and traverse
Student (Name,age)

 import java.util.Collection;import java.util.Iterator;/* *  Requirements: Store strings and traverse them.  *  *  Analysis:  *   a: Creating a Collection Object  *   b: Creating a String Object  *    c: Adding a String object to the collection  *   d: Iterating through the collection  */public class collectiontest {  public static void main (String[] args)  {  //  Create collection Objects    Collection c = new arraylist ();  //  Creating a String Object   //  adding a String object to the collection   c.add ("Brigitte"),   c.add ("Wind"),   c.add ("Elina"),   c.add ("Wu Xin");   C.add ("Lynn Qu");  //  iterate through the collection   //  get the iterator object through the collection object   iterator it =  c.iterator ();  //  the Hasnext () method of the Iterator object to determine if there is no element   while  (It.hasnext ())  {    //  get elements    String s =  (String) through the next () method of an Iterator object   It.next ();    system.out. println (s);   } }} 

The console output in MyEclipse is as follows:

Brigitte

Wind

Elina

Lynn Qu

Do you understand me?

650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0013.gif "alt=" J_0013.gif "/>

This article from "GD" blog, reproduced please contact the author!

Collection Framework (collection store strings and traverse)

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.