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());
    }
}
时间: 2024-08-21 22:03:16

23.LinkedList添加和删除新闻标题的相关文章

添加一行删除一行-js代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

10-表格添加、删除

表格添加.删除 1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>无标题文档</title> 6 <script> 7 window.onload=function () 8 { 9 var oTab=document.getElementById('tab1'); 10 11 var oBtn=document.

模拟C#的事件添加和删除

从<C# Via CLR>中的演化的一个小demo,探索事件的添加和删除原理,简单明了: 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading; 6 using System.Threading.Tasks; 7 8 namespace ExpForEvent001 9 { 10 public sealed cl

python学习之配置文件查看,添加,删除配置程序(作业三)

思维还有点乱,撸代码到深夜,先上代码吧.(我是跟着武sir的思路的) 流程图: 代码(有注释): 1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 import json,os 4 def login(): 5 flag = False 6 while True: 7 username = input("Please enter a user name:") 8 l = open('name_lock.txt','r') 9 for

Dom解析XML(添加,删除,修改,保存)

//XML文件 <?xml version="1.0" encoding="UTF-8" ?><PhoneInfo> <Brand name="华为"> <Type name="P9"> <title>标题信息</title> </Type> </Brand> <Brand name="苹果"> &l

20.ArrayList获取并打印新闻标题

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

Arrays.asList () 不可添加或删除元素的原因

Java中奖数组转换为List<T>容器有一个很方便的方法 Arrays.asList(T ... a),我通过此方法给容器进行了赋值操作,接着对其进行 添加元素,却发现会抛出一个(java.lang.UnsupportedOperationException)异常. 看了一下源码: public static <T> List<T> asList(T... a) { return new ArrayList<T>(a); } 定位到 ArrayList 内

Javascript DOM 03 表格添加、删除 + 搜索

获取 tBodies.tHead.tFoot.rows.cells 隔行变色 鼠标移入高亮 添加.删除一行 DOM方法的使用  添加.删除 1 <script> 2 window.onload=function (){ 3 /*var str='abcdef'; 4 alert(str.search('g')); //找到并且返回字符串出现的位置,如果没找到-1 5 */ 6 /* 7 var str='abc 123 ert'; 8 var arr=str.split(' '); 9 ale

vue添加和删除

实现添加和删除操作: 1 <!DOCTYPE html> 2 <html lang="en"> 3 4 <head> 5 <meta charset="UTF-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <meta http-equiv="