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. OneZero第五周第一次站立会议(2016.4.18)

    1. 时间: 13:00--13:15  共计15分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...

  2. BCB将RichEdit光标移到最后一行

    int linecount=RichEdit1->Lines->Count; RichEdit1-> SelStart=SendMessage(RichEdit1-> Hand ...

  3. Ubuntu17安装maven3.5.2

    1.下载maven 源码文件.tar.gz 2.解压源文件sudo tar -zxvf .tar.gz文件 3.配置/etc/profile文件 export MAVEN_HOME=/app/java ...

  4. 使用ETL构建数据仓库的思考

    使用ETL构建数据仓库的思考 背景:公司的数据仓库建设项目启动在即,所谓万事开头难,如何在我们数仓建设规划的前期做好业务数据准备和系统建设规划是我们需要思考的问题,这里根据之前的自己参与过的公司ODS ...

  5. 【bzoj3881】[Coci2015]Divljak AC自动机+树链的并+DFS序+树状数组

    题目描述 Alice有n个字符串S_1,S_2...S_n,Bob有一个字符串集合T,一开始集合是空的. 接下来会发生q个操作,操作有两种形式: “1 P”,Bob往自己的集合里添加了一个字符串P. ...

  6. redis scan迭代模糊匹配

    $redis = new Redis(); $redis->connect('localhost', 6379); $iterator = null; while (true) { $keys ...

  7. 自学Aruba1.2-WLAN一些基本常识802.11n速率计算方式、802.11n及802.11AC速率表

    点击返回:自学Aruba之路 自学Aruba1.2-WLAN一些基本常识802.11n速率计算方式.802.11n及802.11AC速率表 1. 802.11n速率计算方式 以802.11g的54M最 ...

  8. luogu1328 [NOIp2014]生活大爆炸版石头剪刀布 (模拟)

    #include<bits/stdc++.h> #define pa pair<int,int> #define CLR(a,x) memset(a,x,sizeof(a)) ...

  9. 【bzoj3992】 SDOI2015—序列统计

    http://www.lydsy.com/JudgeOnline/problem.php?id=3992 (题目链接) 题意 集合${S}$中有若干个不超过${m}$的非负整数,问由这些数组成一个长度 ...

  10. 前端学习 -- Css -- 内联元素的盒模型

    内联元素不能设置width和height: 设置水平内边距,内联元素可以设置水平方向的内边距:padding-left,padding-right: 垂直方向内边距,内联元素可以设置垂直方向内边距,但 ...