Skip to content

Commit

Permalink
Merge pull request #581 from dejavuhyo/patch-2024-11-29
Browse files Browse the repository at this point in the history
feat(posts): create 2024-11-29-java-array-value
  • Loading branch information
dejavuhyo authored Nov 29, 2024
2 parents 7c124c7 + 3d84cd9 commit 29a7570
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions _posts/java/2024-11-29-java-array-value.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: Java 2차원 배열 값 출력
author: dejavuhyo
date: 2024-11-29 11:15:00 +0900
categories: [Language, Java]
tags: [java-array, array, array-value, 자바-배열, 배열, 배열-값]
---

2024-11-29-java-array-value.md

## 1. 반복문
이중 for문을 사용하여 값을 출력 한다.

* 예제

```java
public class Test {
public static void main(String[] args) {
int[][] ary = {{1, 2}, {3, 4, 5}, {6, 7, 8, 9}};
for (int[] ar : ary) {
for (int val : ar) {
System.out.println(val);
}
}
}
}
```

* 결과

```text
1
2
3
4
5
6
7
8
9
```

## 2. Arrays.deepToString()
`java.util.Arrays.deepToString()` 메소드를 사용하여 2차원 배열 값을 문자열로 출력 한다.

* 예제

```java
import java.util.Arrays;

public class Test {
public static void main(String[] args) {
int[][] ary = {{1, 2}, {3, 4, 5}, {6, 7, 8, 9}};
System.out.println(Arrays.deepToString(ary));
}
}
```

* 결과

```text
[[1, 2], [3, 4, 5], [6, 7, 8, 9]]
```

## [출처 및 참고]
* [https://hianna.tistory.com/511](https://hianna.tistory.com/511)

0 comments on commit 29a7570

Please sign in to comment.