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.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.ArrayList;
import java.util.List;

import entity.NewTitle;

public class NewTitleDemo {

    public static void main(String[] args) {
        // 具体实现步骤
        // 1、创建多个各类新闻标题对象
        NewTitle car = new NewTitle(1, "汽车", "管理员");
        NewTitle test = new NewTitle(2, "高考", "管理员");
        // 2、创建存储各类新闻标题的集合对象
        List newsTitleList = new ArrayList();
        // 3、按照顺序依次添加各类新闻标题
        newsTitleList.add(car);
        newsTitleList.add(test);
        // 4、获取新闻标题的总数
        System.out.println("新闻标题数目为:" + newsTitleList.size() + "条");
        // 5、根据位置获取相应新闻标题、逐条打印每条新闻标题的名称,也就是我们常说的遍历集合对象
        for (int i = 0; i < newsTitleList.size(); i++) {
            NewTitle title = (NewTitle) newsTitleList.get(i);
            System.out.println(i + 1 + ":" + title.getTitleName());
        }

    }

}
时间: 2024-08-05 11:16:14

20.ArrayList获取并打印新闻标题的相关文章

获取全部校园新闻(GZCC大新闻流量刷新器)

import requests import re url = "http://news.gzcc.cn/html/xiaoyuanxinwen/" listnewurl = "http://news.gzcc.cn/html/xiaoyuanxinwen/index.html" res = requests.get(url) reslist = requests.get(listnewurl) res.encoding = 'utf-8' # 利用Beautifu

Fragment在Activity中跳转,实现类似新闻标题跳转新闻内容功能

1.准备的工作,新闻数据类,新闻数据适配器,适配器的布局: News.java package com.example.zps.fourfragmentbestpractice; /** * Created by zps on 2015/9/1. */ public class News { private String title; private String content; public String getTitle() { return title; } public void se

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

2016.5.28 新闻发布系统显示新闻标题

<?php mysql_connect("localhost", "用户名", "密码");      //连接数据库管理系统 mysql_select_db("member");                                   //选择数据库 mysql_query("set character set utf8");                     //设置数据库的字体

crawler4j源码学习(1):搜狐新闻网新闻标题采集爬虫

crawler4j是用Java实现的开源网络爬虫.提供了简单易用的接口,可以在几分钟内创建一个多线程网络爬虫.下面实例结合jsoup,采集搜狐新闻网(http://news.sohu.com/)新闻标题信息. 所有的过程仅需两步完成: 第一步:建立采集程序核心部分 1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See

获取全部校园新闻(补)

1.取出一个新闻列表页的全部新闻 包装成函数. 2.获取总的新闻篇数,算出新闻总页数. 3.获取全部新闻列表页的全部新闻详情. 4.找一个自己感兴趣的主题,进行数据爬取,并进行分词分析.不能与其它同学雷同. 1-3: import requests from bs4 import BeautifulSoup from datetime import datetime import re listPageUrl = "http://news.gzcc.cn/html/xiaoyuanxinwen/

【PHP爬虫】curl+simple_html_dom 抓取百度最新消息新闻标题,来源,URL

<title>新闻转载统计</title> <script> function submit(){ wd=document.getElementById('name').value; page=document.getElementById('page').value; source=document.getElementById('source').value; window.location.href='getbaidu.php?wd='+wd+'&page

获取全部校园新闻

1.取出一个新闻列表页的全部新闻 包装成函数. 2.获取总的新闻篇数,算出新闻总页数. 3.获取全部新闻列表页的全部新闻详情. import requests from bs4 import BeautifulSoup from datetime import datetime import re # 获取新闻点击次数 def getNewsId(url): newsId = re.findall(r'\_(.*).html', url)[0][-4:] clickUrl = 'http://o

python爬虫:使用urllib.request和BeautifulSoup抓取新浪新闻标题、链接和主要内容

案例一 抓取对象: 新浪国内新闻(http://news.sina.com.cn/china/),该列表中的标题名称.时间.链接. 完整代码: from bs4 import BeautifulSoup import requests url = 'http://news.sina.com.cn/china/' web_data = requests.get(url) web_data.encoding = 'utf-8' soup = BeautifulSoup(web_data.text,'