20.ArrayList Get and print news headlines

Source: Internet
Author: User

 Packageentity; Public classNewtitle {Private intId//ID    PrivateString TitleName;//name    PrivateString creater;//created by     PublicNewtitle () {} PublicNewtitle (intID, String titlename, String creater) {         This. ID =ID;  This. TitleName =TitleName;  This. creater =creater; }     Public intgetId () {returnID; }     Public voidSetId (intID) { This. ID =ID; }     PublicString Gettitlename () {returnTitleName; }     Public voidsettitlename (String titlename) { This. TitleName =TitleName; }     PublicString Getcreater () {returncreater; }     Public voidSetcreater (String creater) { This. creater =creater; }    }
 Packagetest;Importjava.util.ArrayList;Importjava.util.List;Importentity. Newtitle; Public classNewtitledemo { Public Static voidMain (string[] args) {//Concrete Implementation Steps//1. Create multiple kinds of news title objectsNewtitle car =NewNewtitle (1, "Car", "admin"); Newtitle Test=NewNewtitle (2, "college entrance", "admin"); //2. Create a Collection object that stores all kinds of news headlinesList newstitlelist =NewArrayList (); //3, in order to add a variety of news headlinesNewstitlelist.add (CAR);        Newstitlelist.add (test); //4. Get the total number of news headlinesSystem.out.println ("Number of news headlines:" + newstitlelist.size () + "bar"); //5, according to the location to obtain the corresponding news title, one-to-print the name of each news title, that is, we often say the traversal of the collection object         for(inti = 0; I < newstitlelist.size (); i++) {newtitle title=(newtitle) newstitlelist.get (i); System.out.println (i+ 1 + ":" +title.gettitlename ()); }    }}

20.ArrayList Get and print news headlines

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.