Skip to content

Commit 77c0a54

Browse files
committed
优化“输出 Java 数组最简单的方式”
1 parent 059ed8f commit 77c0a54

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ stackoverflow-Java-top-qa
5151
* [如何用一行代码初始化一个ArrayList](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/initialization-of-an-arraylist-in-one-line.md)
5252
* [初始化静态map](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/How-can-I-Initialize-a-static-Map.md)
5353
* [给3个布尔变量,当其中有2个或者2个以上为true才返回true](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/Check-if-at-least-two-out-of-three-booleans-are-true.md)
54-
* [Java中打印一个数组最简单的方法是什么](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/What's-the-simplest-way-to-print-a-Java-array.md)
54+
* [输出 Java 数组最简单的方式](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/What's-the-simplest-way-to-print-a-Java-array.md)
5555
* [为什么以下用随机生成的文字会得出 “hello world”?](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/why-does-this-code-using-random-strings-print-hello-world.md)
5656
* [什么在java中存放密码更倾向于char[]而不是String](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/why-is-cha[]-preferred-over-String-for-passwords-in-java.md)
5757
* [如何避免在JSP文件中使用Java代码](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/how-to-avoid-java-code-in-jsp-files.md)

contents/What's-the-simplest-way-to-print-a-Java-array.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
Java中打印一个数组最简单的方法是什么
1+
输出 Java 数组最简单的方式
22
===
33
问题
44
---
5-
在java中,数组没有重写toString()方法,所以我如果直接调用数组toStrign()方法的话,只会得到它的内存地址。像这样:
5+
因为 Java 数组中没有 toString() 方法,所以我如果直接调用数组toStrign()方法的话,只会得到它的内存地址。像这样,显得并不人性化:
66
```java
77
int[] intArray = new int[] {1, 2, 3, 4, 5};
88
System.out.println(intArray); // 有时候会输出 '[I@3343c8b3'
99
```
10-
但是实际上我想要的输出效果是
11-
```java
12-
[1, 2, 3, 4, 5]
13-
```
14-
所以打印一个数组最简单的方法是什么?我想要的效果是
10+
11+
所以输出一个数组最简单的方法是什么?我想要的效果是
1512
```java
1613
// 数字数组:
1714
int[] intArray = new int[] {1, 2, 3, 4, 5};
@@ -24,7 +21,7 @@ String[] strArray = new String[] {"John", "Mary", "Bob"};
2421

2522
回答
2623
---
27-
在JAVA5中使用 Arrays.toString(arr) 或 Arrays.deepToString(arr)来打印数组
24+
在 Java 5+ 以上中使用 Arrays.toString(arr) 或 Arrays.deepToString(arr)来打印(输出)数组
2825

2926
不要忘了引入import java.util.Arrays;
3027
```java

0 commit comments

Comments
 (0)