23.LinkedList adding and removing 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.LinkedList;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 Medical=NewNewtitle (2, "medicine", "Administrator"); //2. Create a Collection object that stores all kinds of news headlinesLinkedList newstitlelist =NewLinkedList (); //3. Add headline news headlines and end titlesNewstitlelist.addfirst (CAR);        Newstitlelist.addlast (medical); //4. Get headlines and last news headlinesNewtitle first =(Newtitle) Newstitlelist.getfirst (); System.out.println (The headline headlines are: "+first.gettitlename ()); Newtitle Last=(Newtitle) newstitlelist.getlast (); System.out.println ("The last news headline is:" +last.gettitlename ()); //5. Delete Headlines and last news headlinesNewtitle firstnews=(Newtitle) Newstitlelist.removefirst (); System.out.println ("Deleted Headlines headline:" +firstnews.gettitlename ()); Newtitle lastnews=(Newtitle) newstitlelist.removelast (); System.out.println ("The last news title deleted is:" +lastnews.gettitlename ()); System.out.println ("Number of news bars left after deletion:" +newstitlelist.size ()); }}

23.LinkedList adding and removing 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.