Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
bowbahdoe committed Sep 17, 2024
1 parent 996f1d6 commit 5572d10
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/arrays/empty_array.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
If you use an array initializer that has no elements between the `{` and `}`
you can create an empty array.

```java
```java,no_run
char[] emptyCharArray = {};
```

An empty array is very similar to an empty `String`. It has a length of 0, it has no elements,
and it is generally useful only as a placeholder value for when you have no data yet but will
be able to reassign the variable holding it when you get some.

```java
```java,panics
~void main() {
char[] emptyCharArray = {};
// 0
System.out.println(emptyCharArray.length);
// Crash
System.out.println(emptyCharArray[0]);
~}
```

0 comments on commit 5572d10

Please sign in to comment.