Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(posts): create 2024-11-29-java-array-value #581

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)