Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c56f242

Browse files
committed
🎉 init
1 parent d937767 commit c56f242

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

‎README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
11
# java-util-collections-explain
22
explain for java.util.Collections
3+
4+
## sort(List<T> list)
5+
6+
- `list` 排序
7+
- 实体需要实现 `Comparable` 接口
8+
9+
## sort(List<T> list, Comparator<? super T> c)
10+
11+
- `list` 排序
12+
- 排序规则器 `Comparator`
13+
14+
## binarySearch(List<? extends Comparable<? super T>> list, T key)
15+
16+
- `List` 实现了 `RandomAccess` 接口或者数量小于 `5000` 按照下标查找,其他情况按照迭代器查找。
17+
18+
## binarySearch(List<? extends T> list, T key, Comparator<? super T> c)
19+
20+
-`binarySearch(List<? extends Comparable<? super T>> list, T key)` 不同的是是否有实现排序规则
21+
22+
## reverse(List<?> list)
23+
24+
- `list` 反序
25+
- `List` 实现了 `RandomAccess` 接口或者数量小于 `18` ,循环一半去调换位置的值, 其他情况使用迭代器。
26+
27+
## shuffle(List<?> list)
28+
29+
- 乱序 `list`
30+
- `List` 实现了 `RandomAccess` 接口或者数量小于 `5`,位置替换,其他情况使用迭代器。
31+
32+
## shuffle(List<?> list, Random rnd)
33+
34+
-`shuffle(List<?> list)` 增加了参数 `Random`
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package edu.maskleo.collections.explain;
2+
3+
import java.util.Arrays;
4+
import java.util.Random;
5+
6+
public class ReverseTest {
7+
8+
public static void main(String[] args) {
9+
java.util.Random random = new Random();
10+
Integer[] arr = new Integer[10];
11+
for (int i = 0; i < 10; i++) {
12+
arr[i] = random.nextInt(100);
13+
}
14+
System.out.println(Arrays.asList(arr));
15+
for (int i=0, mid=arr.length>>1, j=arr.length-1; i<mid; i++, j--) {
16+
int t = arr [i];
17+
arr [i] = arr[j];
18+
arr [j] = t;
19+
}
20+
System.out.println(Arrays.asList(arr));
21+
}
22+
23+
}

‎test/test.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /