1.java.util  2.队列先进先出,栈堆先进后出   3.链表  4.LinkedList  5.TreeSet  6.Comparable  7.Map  8.next()

1.AC 2.A 3.D 4.B 5.D 6.C 7.C 8.C 9.CD

1.× 2.√ 3.× 4.× 5.√ 6.√ 7.√ 8.× 9.√ 10.× 11.× 12.√

2.List是有序的集合,使用此接口能够精确控制每个元素插入的位置,用户能够用索引来访问List中的元素,这类似于java的数组。

Set是一种不包含重复的元素的集合,即任意的两个元素都有equals()方法,Set最多有一个null元素。

Map接口,将键映射到值的对象。一个映射不能包含重复的键;每个键最多只能映射到一个值。

3.区别:Vector是线程安全的,效率低。ArrayList是线程不安全的,效率高。

联系:底层都是数组实现的。

4.Hashtable是JDK1.0版本出现的,是线程安全的,效率低;

HashMap是JDK1.2版本出现的,是线程不安全的,效率高;

Hashtable不可以存储null键和null值;

HashMap可以存储null键和null值(目的是为了让后续代码可以继续执行)

package com.zuikc.bean;

public class Book {
private int id;
private String name;
private double price;
private String press; public Book() {
super();
// TODO Auto-generated constructor stub
} public Book(int id, String name, double price, String press) {
super();
this.id = id;
this.name = name;
this.price = price;
this.press = press;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public double getPrice() {
return price;
} public void setPrice(double price) {
this.price = price;
} public String getPress() {
return press;
} public void setPress(String press) {
this.press = press;
} @Override
public String toString() {
return "Book [id=" + id + ", name=" + name + ", price=" + price + ", press=" + press + "]";
} @Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((press == null) ? 0 : press.hashCode());
long temp;
temp = Double.doubleToLongBits(price);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
} @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Book other = (Book) obj;
if (id != other.id) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
if (press == null) {
if (other.press != null) {
return false;
}
} else if (!press.equals(other.press)) {
return false;
}
if (Double.doubleToLongBits(price) != Double.doubleToLongBits(other.price)) {
return false;
}
return true;
} } package com.zuikc.kehoutest; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import com.zuikc.bean.Book; public class Test6 { public static void main(String[] args) {
// demo1();
Map<Integer, Book> m = new HashMap<>();
m.put(100, new Book(100,"b1",20.5,"aaa"));
m.put(101, new Book(101,"b2",21.5,"bbb"));
m.put(102, new Book(102,"b3",22.5,"ccc"));
m.put(103, new Book(103,"b4",23.5,"ddd")); for(Entry<Integer, Book> entry : m.entrySet()) {
System.out.println(entry.getKey() + "..." + entry.getValue());
}
} private static void demo1() {
List<Book> list = new ArrayList<>();
list.add(new Book(100,"b1",20.5,"aaa"));
list.add(new Book(101,"b2",21.5,"bbb"));
list.add(new Book(102,"b3",22.5,"ccc"));
list.add(new Book(103,"b4",23.5,"ddd")); for (Book book : list) {
System.out.println(book.toString());
}
} }
package com.zuikc.bean;

public class Book {
private int id;
private String name;
private double price;
private String press; public Book() {
super();
// TODO Auto-generated constructor stub
} public Book(int id, String name, double price, String press) {
super();
this.id = id;
this.name = name;
this.price = price;
this.press = press;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public double getPrice() {
return price;
} public void setPrice(double price) {
this.price = price;
} public String getPress() {
return press;
} public void setPress(String press) {
this.press = press;
} @Override
public String toString() {
return "Book [id=" + id + ", name=" + name + ", price=" + price + ", press=" + press + "]";
} @Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((press == null) ? 0 : press.hashCode());
long temp;
temp = Double.doubleToLongBits(price);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
} @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Book other = (Book) obj;
if (id != other.id) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
if (press == null) {
if (other.press != null) {
return false;
}
} else if (!press.equals(other.press)) {
return false;
}
if (Double.doubleToLongBits(price) != Double.doubleToLongBits(other.price)) {
return false;
}
return true;
} } package com.zuikc.kehoutest; import java.util.HashMap;
import java.util.HashSet;
import java.util.TreeSet; import com.zuikc.bean.Book; public class Test7 { public static void main(String[] args) {
// demo1();
TreeSet<Book> ts = new TreeSet<>();
ts.add(new Book(100,"b1",20.5,"aaa"));
ts.add(new Book(100,"b1",20.5,"aaa"));
ts.add(new Book(101,"b2",21.5,"bbb"));
ts.add(new Book(101,"b2",21.5,"bbb"));
ts.add(new Book(102,"b3",22.5,"ccc"));
ts.add(new Book(103,"b4",23.5,"ddd")); for(Book book : ts) {
System.out.println(book);
}
} private static void demo1() {
HashSet<Book> hs = new HashSet<>();
hs.add(new Book(100,"b1",20.5,"aaa"));
hs.add(new Book(101,"b2",21.5,"bbb"));
hs.add(new Book(102,"b3",22.5,"ccc"));
hs.add(new Book(103,"b4",23.5,"ddd")); for(Book book : hs) {
System.out.println(book);
}
} }
package com.zuikc.bean;

public class StudentEntry {
private int key;
private Student2 s;
public StudentEntry() {
super();
// TODO Auto-generated constructor stub
}
public StudentEntry(int key, Student2 s) {
super();
this.key = key;
this.s = s;
}
public int getKey() {
return key;
}
public void setKey(int key) {
this.key = key;
}
public Student2 getS() {
return s;
}
public void setS(Student2 s) {
this.s = s;
} } package com.zuikc.kehoutest; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import com.zuikc.bean.Student2;
import com.zuikc.bean.StudentEntry; public class Test8 { public static void main(String[] args) {
// listToMap();
Map<Integer, Student2> m = new HashMap<>();
m.put(100, new Student2(100, "张三", 23, "男"));
m.put(101, new Student2(101, "李四", 24, "男"));
m.put(102, new Student2(100, "王五", 25, "男"));
m.put(103, new Student2(100, "赵六", 26, "男")); List<StudentEntry> list = new ArrayList<>();
for(Entry<Integer, Student2> entry : m.entrySet()) {
StudentEntry se = new StudentEntry();
se.setKey(entry.getKey());
se.setS(entry.getValue());
list.add(se);
}
for(StudentEntry se : list) {
System.out.println(se.getKey() + "..." + se.getS());
}
} private static void listToMap() {
List<Student2> list = new ArrayList<>();
list.add(new Student2(100, "张三", 23, "男"));
list.add(new Student2(101, "李四", 24, "男"));
list.add(new Student2(100, "王五", 25, "男"));
list.add(new Student2(100, "赵六", 26, "男"));
for (Student2 s : list) {
System.out.println(s);
}
Map<Integer, Student2> m = new HashMap<>();
Iterator<Student2> it = list.iterator();
while (it.hasNext()) {
Student2 s1 = it.next();
m.put(s1.getId(), s1);
} Set<Entry<Integer, Student2>> entrySet = m.entrySet();
for (Entry<Integer, Student2> entry : entrySet) {
System.out.println(entry.getKey() + "..." + entry.getValue());
}
} }
package com.zuikc.kehoutest;

import java.util.HashMap;
import java.util.Map; public class Test9 { public static void main(String[] args) {
String str = "aa@sohu.com,bb@163.com,cc@sina.com";
String strs[] = str.split(",");
Map<String, String> emailMap = new HashMap<String, String>();
for (String email : strs) {
String temp[] = email.split("@");
emailMap.put(temp[0], temp[1]);
}
System.out.println(emailMap.toString());
} }
package com.zuikc.bean;

public class Student3 implements Comparable<Student3>{
private int id;
private String name;
private int age;
public Student3() {
super();
// TODO Auto-generated constructor stub
}
public Student3(int id, String name, int age) {
super();
this.id = id;
this.name = name;
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Student3 [id=" + id + ", name=" + name + ", age=" + age + "]";
}
@Override
public int compareTo(Student3 s) {
return this.age - s.age;
} }
package com.zuikc.kehoutest; import java.util.Scanner;
import java.util.Set; import javax.swing.text.html.HTMLDocument.Iterator; import com.zuikc.bean.Student3; public class Test10 { public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Set<Student3> stuSet = saveStudentInfo();
Iterator<Student3> it = stuSet.iterator();
while (it.hasNext()) {
String info = it.next().toString();
System.out.println(info);
}
} private static void saveStudentInfo() {
while (true) {
System.out.println("请输入学生信息(编号#姓名#年龄)");
String line = sc.nextLine();
if ("exit".equals(line)) {
break;
}
String[] info = line.split("#");
Student3 stu = new Student3(Integer.parseInt(info[0]), info[1], Integer.parseInt(info[2]));
stuSet.add(stu);
}
return stuSet;
} }

day17作业的更多相关文章

  1. 老男孩Day17作业:后台管理平台编辑表格

    一.作业需求: 后台管理平台 ,编辑表格: 1. 非编辑模式: 可对每行进行选择: 反选: 取消选择 2. 编辑模式: 进入编辑模式时如果行被选中,则被选中的行万变为可编辑状态,未选中的不改变 退出编 ...

  2. python基础一 day17 作业

    # 3.用map来处理字符串列表,把列表中所有人都变成sb,比方alex_sbname=['alex','wupeiqi','yuanhao','nezha']# def func(item):# r ...

  3. Day17作业及默写

    正则表达式练习 1.匹配一篇英文文章的标题 类似 The Voice Of China ([A-Z][a-z]*)( [A-Z][a-z]*)* 2.匹配一个网址 https://www.baidu. ...

  4. day17 作业

    目录 一.编写函数(函数执行的时间用time.sleep(n)模拟) 二.编写装饰器,为函数加上统计时间的功能 三.编写装饰器,为函数加上认证的功能 四.编写装饰器,为多个函数加上认证的功能(用户的账 ...

  5. 【转】django 正则URL 匹配

    django 正则URL 匹配  转自:https://www.cnblogs.com/chenkeven/articles/9305260.html 一.引子 在day17 作业中,我们查看主机详细 ...

  6. python27期day17:re、logging日志模块、作业。

    1.re: 正则就是用一些具有特殊含义的符号组合到一起(称为正则表达式)来描述字符或者字符串的方法.或者说:正则就是用来描述一类事物的规则.(在Python中)它内嵌在Python中,并通过 re 模 ...

  7. python 作业

    Linux day01 计算机硬件知识整理 作业要求:整理博客,内容如下 编程语言的作用及与操作系统和硬件的关系 应用程序->操作系统->硬件 cpu->内存->磁盘 cpu与 ...

  8. python10作业思路及源码:类Fabric主机管理程序开发(仅供参考)

    类Fabric主机管理程序开发 一,作业要求 1, 运行程序列出主机组或者主机列表(已完成) 2,选择指定主机或主机组(已完成) 3,选择主机或主机组传送文件(上传/下载)(已完成) 4,充分使用多线 ...

  9. SQLServer2005创建定时作业任务

    SQLServer定时作业任务:即数据库自动按照定时执行的作业任务,具有周期性不需要人工干预的特点 创建步骤:(使用最高权限的账户登录--sa) 一.启动SQL Server代理(SQL Server ...

随机推荐

  1. Only IPV6 下 使用MSDTC ping 之后 出现 找不到主机的问题

    1. 很奇怪 使用两个虚拟机 进行IPV6测试, 需要验证MSDTC. app的机器名 Win12r2update DB的机器名 Win12r2UpdateDB 2. 在使用ipv4 以及 不进行ho ...

  2. SpringBoot 3.SpringBoot 整合 MyBatis 逆向工程以及 MyBatis 通用 Mapper

    一.添加所需依赖,当前完整的pom文件如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&qu ...

  3. Kivy 中文教程 实例入门 简易画板 (Simple Paint App):0. 项目简介 & 成果展示

    本教程咪博士将带领大家学习创建自己的窗口部件 (widget).最终,我们完成的作品是一个简易的画板程序. 当用 kivy 创建应用时,我们需要仔细思考以下 3 个问题: 我们创建的应用需要处理什么数 ...

  4. 解决Delphi 2010启动时出现cannot create xxxx\EditorLineEnds.ttr问题

    由于在Windows安装了最近的更新(KB2982791, KB2970228)后,Delphi的IDE需要创建的一个文件%TEMP%\EditorLineEnds.ttr会被系统锁定,导致除非重新启 ...

  5. 从0在windows上一次性上传本地整个项目(包含所有文件/文件夹)到 Github

    1.注册并登陆Github. 2.登陆进去之后的页面,点击这个“库”,这表示你在Github上上的代码仓库,我这里已经创建过一个了,所以数量是1 3.在仓库选项卡中,点击“新建”按钮添加一个项目. 4 ...

  6. MySQL -- 主从复制的可靠性与可用性

    主库A执行完成一个事务, 写入binlog ,记为 T1 然后传给从库B,从库B 接收该binlog ,记为 T2 从库B执行完成这个事务,记为 T3 同步延时: T3-T1 同一个事务,在 从库执行 ...

  7. 【CH4201】楼兰图腾

    题目大意:给定一个长度为 N 的序列,从序列中任意挑出三个数,求满足中间的数字值最小(最大)有多少种情况. 题解:建立在值域上的树状数组,从左到右扫描一遍序列,统计出每个点左边有多少个数大于(小于)该 ...

  8. 什么是HTTP协议

    什么是Http协议Http协议即超文本传送协议 (HTTP-Hypertext transfer protocol) .它定义了浏览器(即万维网客户进程)怎样向万维网服务器请求万维网文档,以及服务器怎 ...

  9. Codeforces 923 C. Perfect Security

    http://codeforces.com/contest/923/problem/C Trie树 #include<cstdio> #include<iostream> us ...

  10. Codeforces 338 D. GCD Table

    http://codeforces.com/problemset/problem/338/D 题意: 有一张n*m的表格,其中第i行第j列的数为gcd(i,j) 给出k个数 问在这张表格中是否 有某一 ...