728x90
반응형
[예제] List<String>을 콤마로 연결하여 String으로 변환
Stream과 Collectors.joining을 활용하여 콤마로 연결할 수 있습니다.
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) {
// 샘플 데이터
List<String> exhlNmList = Arrays.asList("Exhibition A", "Exhibition B", "Exhibition C");
// 콤마로 연결
String result = exhlNmList.stream()
.collect(Collectors.joining(","));
// 결과 출력
System.out.println(result); // "Exhibition A,Exhibition B,Exhibition C"
}
}
728x90
반응형
'JAVA' 카테고리의 다른 글
[JAVA] 스트림에서 데이터를 정렬하기 (0) | 2025.01.21 |
---|---|
[JAVA] Collectors.toMap을 사용해 중복 제거 (0) | 2025.01.20 |
[JAVA] boolean / Boolean (0) | 2025.01.12 |
[JAVA] BeanUtils.copyProperties 주의사항 (0) | 2025.01.08 |
[JAVA]BigDecimal null 처리 예제 (0) | 2024.12.23 |