본문 바로가기
개발/워드프레스 l 수익화

[JAVA] 배열 내용을 문자열로 출력하기

by 잡다백과사전 2021. 2. 27.
반응형

배열을 print하면 배열의 hashcode가 출력됨.

배열의 문자열을 출력하려면 toString, deepToString 메소드를 이용.

 

 

import java.util.Arrays; 

public class ArrayExec { 
	public static void main(String[] args) { 
		int[] arr = {5,2,1,6,7}; 
		System.out.println(Arrays.toString(arr)); 
	} 
}
[5, 2, 1, 6, 7]

 

 

import java.util.Arrays; 

public class ArrayExe { 

	public static void main(String[] args) { 
    
		int[][] arr = {{1,2,3,4,5},{5,4,3,2,1}}; 
        
		System.out.println(Arrays.deepToString(arr)); 
        
	} 
}
[[1, 2, 3, 4, 5], [5, 4, 3, 2, 1]] 



출처: https://seongsillvanas.tistory.com/9 [Hello World!]

반응형