java longstream to string list

To convert a LongStream to a List<String> in Java, you can use the mapToObj method to convert each long element to a String and then collect the stream elements into a list using the collect method. Here's an example:

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.LongStream;

public class LongStreamToStringListExample {
    public static void main(String[] args) {
        LongStream longStream = LongStream.of(1L, 2L, 3L, 4L, 5L);

        List<String> stringList = longStream
                .mapToObj(String::valueOf) // Convert each long to a String
                .collect(Collectors.toList()); // Collect into a List

        System.out.println(stringList);
    }
}

Output:

[1, 2, 3, 4, 5]

In this example, we create a LongStream using LongStream.of with some example values. Then, we use mapToObj to convert each long element to a String using the String::valueOf method reference. Finally, we collect the stream elements into a List<String> using collect(Collectors.toList()).

댓글

이 블로그의 인기 게시물

Using the MinIO API via curl

The logs of the kubelet service

Reactjs datetime range picker

How to split a list into chunks of 100 items in JavaScript, 자바스크립트 리스트 쪼개기

In HBase, the "memory to disk" flush operation

운영체제를 개발 방법

dagrun_timeout of Airflow

What are 5 creative things I could do with my kids' art, 아이와 함께하는 창의적 놀이

일본어 회화 1

[OS_Linux_Ubuntu] telnet & ssh 설치와 설정 (installation / configuration)