배열을 문자열로 합치는 방법
기본
String[] color = {"red", "bule", "green", "orange", "yellow"};
String joinString = String.join(", ", color);
List 타입
List<String> color = List.of("red", "bule", "green", "orange", "yellow")
String joinString = String.join(", ", color);
실행결과 :
red, bule, green, orange, yellow
Arrays.toString
String[] color = {"red", "bule", "green", "orange", "yellow"};
String str = Arrays.toString(company);
실행 결과 : [red, bule, green, orange, yellow]
정수/실수 문자열 변환
int[] number = {1, 2, 3, 4};
System.out.println(Arrays.toString(number));
double[] prices = {3.14, 4.0, 1.1};
System.out.println(Arrays.toString(prices));
[1, 2, 3, 4] [3.14, 4.0, 1.1]
'Java' 카테고리의 다른 글
Java - 컬렉션(Collection) (0) | 2024.04.17 |
---|---|
싱글톤 패턴의 이점과 단점 (0) | 2022.08.15 |
상속(Java) (0) | 2022.07.18 |
static 변수 (Java) (0) | 2022.07.13 |
this(Java) (0) | 2022.07.12 |
댓글