zoukankan      html  css  js  c++  java
  • 23.LinkedList添加和删除新闻标题

    package entity;
    
    public class NewTitle {
        private int id;            //ID
        private String titleName;  //名称
        private String creater;    //创建者
        public NewTitle() {
        }
        public NewTitle(int id, String titleName, String creater) {
            this.id = id;
            this.titleName = titleName;
            this.creater = creater;
        }
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getTitleName() {
            return titleName;
        }
        public void setTitleName(String titleName) {
            this.titleName = titleName;
        }
        public String getCreater() {
            return creater;
        }
        public void setCreater(String creater) {
            this.creater = creater;
        }
        
    }
    package test;
    import java.util.LinkedList;
    import entity.NewTitle;
    
    public class NewTitleDemo {
    
        public static void main(String[] args) {
            // 具体实现步骤
            // 1、创建多个各类新闻标题对象
            NewTitle car = new NewTitle(1, "汽车", "管理员");
            NewTitle medical = new NewTitle(2, "医学", "管理员");        
            // 2、创建存储各类新闻标题的集合对象
            LinkedList newsTitleList = new LinkedList();        
            // 3、添加头条新闻标题和末尾标题
            newsTitleList.addFirst(car);
            newsTitleList.addLast(medical);
            // 4、获取头条、以及最末条新闻标题
            NewTitle first = (NewTitle) newsTitleList.getFirst();
            System.out.println("头条的新闻标题为:" + first.getTitleName());
            NewTitle last = (NewTitle) newsTitleList.getLast();
            System.out.println("排在最后的新闻标题为:" + last.getTitleName());
            // 5、删除头条和最末条新闻标题
            NewTitle firstNews=(NewTitle)newsTitleList.removeFirst();
            System.out.println("删除的头条新闻标题为:"+firstNews.getTitleName());
            NewTitle lastNews=(NewTitle)newsTitleList.removeLast();
            System.out.println("删除的末条新闻标题为:"+lastNews.getTitleName());
            System.out.println("删除后剩余的新闻条数:"+newsTitleList.size());
        }
    }
  • 相关阅读:
    Flex 布局教程:语法篇(转载)
    【Go】【Http】Go实现Http相关知识点
    【Git】Git相关开发流程
    【Go】杂七杂八GoLang
    【Go】初识Context与Context键值对的可能情况
    jmeter-通过json提取器 提取所有数据 给下个接口使用
    C# 后台调用存储过程超时处理方法,
    IE11脚本错误-调用的对象无效-
    IE11浏览器arrt,全选反选失效无效修改方法
    如何学习计算机知识
  • 原文地址:https://www.cnblogs.com/xiaotaoxu/p/5536523.html
Copyright © 2011-2022 走看看