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. Python网络编程:IO多路复用

    io多路复用:可以监听多个文件描述符(socket对象)(文件句柄),一旦文件句柄出现变化,即可感知. sk1 = socket.socket() sk1.bind(('127.0.0.1',8001 ...

  2. java学习二 数据类型自动提升 0x开头的数据是 16进制且是int型

    变量只能定义一次,不能定义两次, 变量的作用域:当前的大括号与子括号才有效 变量的作用:存储值,取值 整型:向上自动升级,向下强制降级 char,byte,shot参与运算时候自动提升为int型 因为 ...

  3. Django_基于模块的单例模式

    基于模块的单例模式  原理: Python 的独有特性 : 模块的导入只能生效一次. 再重复导入只要基于一套环境都是使用的 最初 的那份资源.  示例: 文档结构: # mysingleton.py ...

  4. word默认字体与大小

    对于红色地方单击,“正文框”按右键+修改 修改字体大小 修改中文和西文时的字体 注意宋体和宋体 (中文正文)是不同的

  5. LeetCode 7最长公共前缀

    编写一个函数来查找字符串数组中的最长公共前缀. 如果不存在公共前缀,返回空字符串 "". 示例 1: 输入: ["flower","flow" ...

  6. sking

    #include #include #include typedef struct SKI{ int data; int x; int y; char flag; int len; }STSKI; i ...

  7. win32 ini

    原文:https://www.cnblogs.com/qq78292959/archive/2012/06/10/2544389.html Windows操作系统专门为此提供了6个API函数来对配置设 ...

  8. IsNullOrWhiteSpace与IsNullOrEmpty

    public static boolean IsNullOrEmpty(String value) { return (value == null || value.length() == 0);} ...

  9. Training (deep) Neural Networks Part: 1

    Training (deep) Neural Networks Part: 1 Nowadays training deep learning models have become extremely ...

  10. webstorm去掉vue错误提示