使用集合存储信息概论.pptVIP

  • 6
  • 0
  • 约1.31千字
  • 约 22页
  • 2017-06-24 发布于福建
  • 举报
用集合存储对象;为什么需要集合框架;Java集合框架包含的内容;List接口和ArrayList类 ;List接口和ArrayList类 5-2;List接口和ArrayList类 5-3;List接口和ArrayList类 5-4;List接口和ArrayList类 5-5;创建一个类Cat 包含属性name,在构造方法中进行初始化 添加一个方法show(),用以打印name属性的值 创建一个类CatTest,添加main方法,实现 创建一个ArrayList,向其中添加几个Cat对象 遍历该集合,并且对每个Cat对象调用show()方法 ;List接口和LinkedList类 ;List接口和LinkedList类 ;List接口和LinkedList类 3-3;创建一个类Stack,代表堆栈(其特点为:后进先出),添加方法add(Object obj)、以及get(),添加main方法进行验证,要求: 使用LinkedList实现堆栈 在向LinkedList中添加时,使用addLast方法 在从LinkedList中取出时,使用removeLast方法;Map接口和HashMap类 ;Map接口和HashMap类 ;Map接口和HashMap类 4-3;Map接口和HashMap类 4-4;创建一个类Book 包含属性:title(标题),使用构造方法进行初始化 重写toString()方法,用以返回Title属性的值 创建一个类BookTest,添加main方法,要求: 使用HashMap进行存储,键为Book对象的编号,值为Book对象 通过某一个编号获取Book对象,并打印该Book对象的标题 ;使用集合框架注意事项;请给出下面Java代码的运行结果;public class FirstLevelTitleDB { public static void main(String[] args) { FirstLevelTitle car = new FirstLevelTitle(1, 汽车, 管理员, new Date()); FirstLevelTitle test = new FirstLevelTitle(2, 高考, 管理员, new Date()); List newsTitleList = new ArrayList(); newsTitleList.put(car); newsTitleList.put(test); print(newsTitleList); } public static void print(ArrayList newsList) { for (int i = 0; i newsList.size(); i++) { FirstLevelTitle title = (FirstLevelTitle)newsList.get(i); System.out.println(i + 1 + : + title.getTitleName()); } } };Thank you !

文档评论(0)

1亿VIP精品文档

相关文档