[프로그래머스 코딩테스트] 문자 리스트를 문자열로 변환하기

yedy·2023년 5월 11일
0
post-thumbnail

문자 리스트를 문자열로 변환하기

코드

class Solution {
    public String solution(String[] arr) {
        String answer = String.join("", arr);
        return answer;
    }
}

String.join()
합친 문자열을 반환


String[] company = { "Apple", "Amazon", "Google", "Microsoft"};
String joinString = String.join(", ", company);
 
System.out.println(joinString);

Apple, Amazon, Google, Microsoft

List<String> company = List.of("Apple", "Amazon", "Google", "Microsoft");
String joinString = String.join("-", company);
 
System.out.println(joinString);

Apple-Amazon-Google-Microsoft

profile
공주 개발자

0개의 댓글