Skip to content

Commit

Permalink
doc: Update java.md (#240)
Browse files Browse the repository at this point in the history
修正一些文字说明,补充下ConcurrentHashMap的使用
  • Loading branch information
qinxiongzhou committed Dec 20, 2022
1 parent 0c9fb08 commit 8e33072
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions docs/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ boolean[] answers = {true, false};

查看: [Arrays](#java-数组)

### Swap
### 交换变量 Swap

```java
int a = 1;
Expand All @@ -101,7 +101,7 @@ b = temp;
System.out.println(a + " " + b); // 2 1
```

### Type Casting
### 类型转换 Type Casting

```java
// Widening
Expand Down Expand Up @@ -344,7 +344,7 @@ for (int a: arr) {
// 输出: a b c
```

### Multidimensional Arrays
### 二维数组 Multidimensional Arrays

```java
int[][] matrix = { {1, 2, 3}, {4, 5} };
Expand All @@ -359,7 +359,7 @@ for (int i = 0; i < a.length; ++i) {
// 输出: 1 2 3 4 5 6 7
```

### Sort
### 排序 Sort

```java
char[] chars = {'b', 'a', 'c'};
Expand Down Expand Up @@ -547,10 +547,10 @@ for (int i = 0; i < 5; i++) {
Java 框架搜集
--------------------

### Java 搜集
### Java 集合
<!--rehype:wrap-class=col-span-2 row-span-2-->

搜集 | Interface | 有序 | 已排序 | 线程安全 | 复制 | Nullable
集合 | Interface | 有序 | 已排序 | 线程安全 | 复制 | Nullable
:-|:-|:-|:-|:-|:-|:-
[ArrayList](https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html) | List | Y | _N_ | _N_ | Y | Y
[Vector](https://docs.oracle.com/javase/8/docs/api/java/util/Vector.html) | List | Y | _N_ | Y | Y | Y
Expand Down Expand Up @@ -615,6 +615,25 @@ m.forEach((key, value) -> {
});
```

### ConcurrentHashMap

```java
ConcurrentHashMap<Integer, String> m
= new ConcurrentHashMap<>();
m.put(100, "Hello");
m.put(101, "Geeks");
m.put(102, "Geeks");
// 移除
m.remove(101, "Geeks");

// 如果不存在,就添加,存在就不变更
m.putIfAbsent(103, "Hello");

// 替换
m.replace(101, "Hello", "For");
System.out.println(m);
```

### HashSet

```java
Expand Down Expand Up @@ -771,7 +790,7 @@ text.split(Pattern.quote("|"));
`Math.toDegrees(rad)` | 以度为单位的角度弧度
`Math.toRadians(deg)` | 以弧度为单位的角度度

### Try/Catch/Finally
### 异常 Try/Catch/Finally

```java
try {
Expand Down

0 comments on commit 8e33072

Please sign in to comment.