提交 74218dbe 编写于 作者: CSDN-Ada助手's avatar CSDN-Ada助手

中阶8章和9章出题

上级 3c55b40f
{
"node_id": "java-16f140529ddd4709a2bc538fd83d4324",
"keywords": [],
"children": [
{
"WeakHashMap": {
"keywords": [],
"children": [],
"node_id": "java-77540b2eae5f4d25834edcb16f1f22fc",
"title": "WeakHashMap"
}
}
],
"export": [],
"title": "持有引用"
}
\ No newline at end of file
{
"node_id": "java-4d469275970748d68a5e3e51ba8728f4",
"keywords": [],
"children": [
{
"一种Generator解决方案": {
"keywords": [],
"children": [],
"node_id": "java-873bf34ed07045bba19f3535e4d866f6",
"title": "一种Generator解决方案"
}
},
{
"Map生成器": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "Map生成器"
}
},
{
"使用Abstract类": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "使用Abstract类"
}
}
],
"export": [],
"title": "填充容器"
}
\ No newline at end of file
{
"node_id": "java-62b6b4f057f549d5b3a4498ef6c7a7e8",
"keywords": [],
"children": [
{
"未获支持的操作": {
"keywords": [],
"children": [],
"node_id": "java-2031010f8362415e9db1c070711e5fd1",
"title": "未获支持的操作"
}
}
],
"export": [],
"title": "可选操作"
}
\ No newline at end of file
{
"node_id": "java-10969a6ccab543558603a3c5d149cb1c",
"keywords": [],
"children": [
{
"理解hashCode()": {
"keywords": [],
"children": [],
"node_id": "java-11f8416ef79f4128998d905e5c178b13",
"title": "理解hashCode()"
}
},
{
"为速度而散列": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "为速度而散列"
}
},
{
"覆盖hashCode()": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "覆盖hashCode()"
}
}
],
"export": [],
"title": "散列与散列码"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "Collection.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# Collection
下列关于Collection功能方法的说法错误的是:
## 答案
```
Arrays.asList()
可以将数组转换为list,之后可以像操作普通List一样对其进行增删改查。
```
## 选项
### A
```
Object[] toArray()
返回一个数组,该数组包含容器中的所有元素
```
### B
```
boolean isEmpty()
判断容器是否为空,容器中没有元素时返回true,与size()==0时效果相同
```
### C
```
boolean removeAll(Collection<?>)
移除参数中的所有元素,只要有一个移除成功就返回true
```
......@@ -2,6 +2,6 @@
"node_id": "java-e4ee5c02d364431f901c2851e2bebdc0",
"keywords": [],
"children": [],
"export": [],
"export": ["Collection.md"],
"title": "Collection的功能方法"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "List.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# List
下列关于 `List` 功能方法的说法正确的是:
## 答案
```
以上说法均正确
```
## 选项
### A
```
add(int, E)
将指定的元素添加到此列表的索引位置,索引后面的元素位置向后偏移
```
### B
```
subList(int fromIndex, int toIndex)
该方法返回的是父list一个视图,操作视图会同步到父list
```
### C
```
ListIterator迭代器接口的add(E)
将指定的元素插入列表,插入位置为迭代器当前位置之前
```
......@@ -2,6 +2,6 @@
"node_id": "java-6a6a4fabc4e34b5d985e4787fda4793f",
"keywords": [],
"children": [],
"export": [],
"export": ["List.json"],
"title": "List的功能方法"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "Set.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# Set
下列关于 `Set` 说法正确的是:
## 答案
```
LinkedHashSet能保证元素的次序
```
## 选项
### A
```
HashSet查找速度快,且能保证有序
```
### B
```
TreeSet底层为树结构,能保证元素的次序
```
### C
```
SortedSet实现了Set接口
```
......@@ -2,6 +2,6 @@
"node_id": "java-d29c64a86fbb49b88cc2eaa7b39375b4",
"keywords": [],
"children": [],
"export": [],
"title": "完整的容器分类法"
"export": ["Set.json"],
"title": "Set和存储顺序"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "Queue.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# Queue
下列代码用优先级队列实现了任务队列,运行程序控制台输出正确的是:
```java
class Task {
private String name;
private int priority;
public Task(String name, int priority) {
this.name = name;
this.priority = priority;
}
// 此处省略getter和setter方法
}
public class CollectionsTest {
public static void main(String[] args) {
Comparator<Task> cmp = new Comparator<Task>() {
public int compare(Task o1, Task o2) {
int diff = o1.getPriority() - o2.getPriority();
if (diff > 0) {
return -1;
} else if (diff == 0) {
return 0;
}
return 1;
}
};
Queue<Task> queue = new PriorityQueue<>(cmp);
queue.add(new Task("a", 8));
queue.add(new Task("b", 2));
queue.add(new Task("c", 6));
queue.add(new Task("d", 1));
while (!queue.isEmpty()) {
Task task = queue.poll();
System.out.print(task.getName());
}
}
}
```
## 答案
```
acbd
```
## 选项
### A
```
dbca
```
### B
```
bdca
```
### C
```
acdb
```
{
"node_id": "java-3b1d3953fd724d1f87c1e95918bc2d0c",
"keywords": [],
"keywords": ["队列", "queue"],
"children": [
{
"优先级队列": {
......@@ -19,6 +19,6 @@
}
}
],
"export": [],
"export": ["Queue.json"],
"title": "队列"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "Map.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# Map
下列关于 `Map` 说法, 能提高性能的是:
## 答案
```
增大map大小
```
## 选项
### A
```
提高链地址法的链表的长度
```
### B
```
遇冲突再hash
```
### C
```
减小负载因子的大小
```
......@@ -27,6 +27,6 @@
}
}
],
"export": [],
"export": ["Map.json"],
"title": "理解Map"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "Select.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# 选择接口的不同实现
下列关于集合接口的不同实现的选择错误的是:
## 答案
```
HashMap是线程安全的
```
## 选项
### A
```
ArrayList底层由数组支持,能按照索引查找,查找速度更快
```
### B
```
当需要保持唯一,切能按照大小排序,可以选择TreeSet
```
### C
```
当需要对map的key或者value实现自定义排序时,可以选择LinkedHashMap
```
......@@ -41,6 +41,6 @@
}
}
],
"export": [],
"export": ["Select.json"],
"title": "选择接口的不同实现"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "StaticMethod.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# Collections实用方法
下列关于Collections的实用方法,说法正确的是:
## 答案
```
以上说法均正确
```
## 选项
### A
```
Collections.sort(list)
可以实现对list的排序
```
### B
```
Collections.unmodifiableCollection()
可以设定Collections不可修改
```
### C
```
Collections.synchronizedCollection()
可以实现对Collections的同步控制
```
......@@ -27,6 +27,6 @@
}
}
],
"export": [],
"title": "实用方法"
"export": ["StaticMethod.json"],
"title": "Collections实用方法"
}
\ No newline at end of file
{
"node_id": "java-a5ad5ac879014d99b56546a687064de9",
"keywords": [],
"children": [],
"export": [],
"title": "CountDownLatch"
}
\ No newline at end of file
{
"node_id": "java-626f8873229c4ebcbf9535893b3a2636",
"keywords": [],
"children": [],
"export": [],
"title": "CyclicBarrier"
}
\ No newline at end of file
{
"node_id": "java-d78ab239f1af4ea9a947bb073e25466f",
"keywords": [],
"children": [],
"export": [],
"title": "DelayQueue"
}
\ No newline at end of file
{
"node_id": "java-ba4040d7af8d408aa6f26827ce977b93",
"keywords": [],
"children": [],
"export": [],
"title": "PriorityBlockingQueue"
}
\ No newline at end of file
{
"node_id": "java-7a2655c558a94868acfd5c47605c19df",
"keywords": [],
"children": [],
"export": [],
"title": "ScheduledExecutor"
}
\ No newline at end of file
{
"node_id": "java-c696f5c80c8f49eab7d45be97d02a9b4",
"keywords": [],
"children": [],
"export": [],
"title": "Semaphore"
}
\ No newline at end of file
{
"node_id": "java-0b97e56a58b94d2da9dd53bb9b1baac6",
"keywords": [],
"children": [],
"export": [],
"title": "Exchange"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "ScheduledExecutor.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# ScheduledExecutor
项目中经常与遇到定时执行任务的情况,可以使用 `ScheduledExecutor` 来实现,以下代码运行后制台输出正确的是:
```java
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
class Task implements Runnable {
private String name;
public Task(String name) {
this.name = name;
}
@Override
public void run() {
System.out.println(name);
}
}
public class ScheduledExecutorTest {
public static void main(String[] args) {
ScheduledThreadPoolExecutor schedule = new ScheduledThreadPoolExecutor(10);
for (int i = 5; i > 0; i--) {
Task worker = new Task("task-" + i);
schedule.schedule(worker, i*2, TimeUnit.SECONDS);
}
}
}
```
## 答案
```
task-1
task-2
task-3
task-4
task-5
```
## 选项
### A
```
task-5
task-4
task-3
task-2
task-1
```
### B
```
task-5
task-4
task-1
task-2
task-3
```
### C
```
task-1
task-2
task-3
task-5
task-4
```
{
"node_id": "java-5a49d27c4caa4300936968edb642186c",
"keywords": [],
"keywords": ["CountDownLatch", "CyclicBarrier", "DelayQueue", "PriorityBlockingQueue", "ScheduledExecutor", "Semaphore", "Exchanger"],
"children": [
{
"性能测试框架": {
"CountDownLatch": {
"keywords": [],
"children": [],
"node_id": "java-9a7cb3066def45889807e133e5eb7736",
"title": "性能测试框架"
"title": "CountDownLatch"
}
},
{
"对List的选择": {
"CyclicBarrier": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "对List的选择"
"node_id": "java-626f8873229c4ebcbf9535893b3a2636",
"title": "CyclicBarrier"
}
},
{
"微基准测试的危险": {
"DelayQueue": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "微基准测试的危险"
"node_id": "java-d78ab239f1af4ea9a947bb073e25466f",
"title": "DelayQueue"
}
},
{
"对Set的选择": {
"PriorityBlockingQueue": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8"
"node_id": "java-ba4040d7af8d408aa6f26827ce977b93",
"title": "PriorityBlockingQueue"
}
},
{
"对Map的选择": {
"ScheduledExecutor": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8"
"node_id": "java-7a2655c558a94868acfd5c47605c19df",
"title": "ScheduledExecutor"
}
},
{
"Semaphore": {
"keywords": [],
"children": [],
"node_id": "java-c696f5c80c8f49eab7d45be97d02a9b4",
"title": "Semaphore"
}
},
{
"Exchanger": {
"keywords": [],
"children": [],
"node_id": "java-0b97e56a58b94d2da9dd53bb9b1baac6",
"title": "Exchanger"
}
}
],
"export": [],
"export": ["ScheduledExecutorTest.json"],
"title": "新类库中的构件"
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册