1. String 문자열 데이터의 결합
public class Solution {
String str1 ="컴퓨터";
String str2 ="본체";
String strData =String.join("", str1, str2);
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Solution s = new Solution();
System.out.println(s.strData);
}
}
출력결과
컴퓨터본체
2. ArrayList 리스트(List)요소의 결합
public class Solution {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList();
list.add("어기야");
list.add("디어차");
String listData = String.join("^", list);
System.out.println(listData);
}
}
출력결과
어기야^디어차
3. Array 고정 배열 요소의 결합
public class Solution {
public static void main(String[] args) {
String array[] = new String[2];
array[0]="우리집";
array[1]="나비";
String arrayData = String.join("&", array);
System.out.println(arrayData);
}
}
출력결과
우리집&나비
'자바 알고리즘 > 알고리즘 직빵 자바 문법' 카테고리의 다른 글
삼항 연산자 vs if ~else구문 (0) | 2022.11.25 |
---|---|
[Java] char 배열을 String 문자열로 변환하기(3가지) (0) | 2022.11.25 |
배열을 리스트로, 리스트를 배열로 -stream() 이용★★ (1) | 2022.11.24 |
String문자열 int형 배열로 만들기-초빈출★★ (0) | 2022.11.24 |
문자열에서 숫자만 남기기-초빈출★★ (0) | 2022.11.24 |