Java 中将整数列表转换为字符串列表的程序

java 8object oriented programmingprogramming更新于 2025/12/3 21:32:17

这是我们的整数列表 −

List<Integer> listInteger = Arrays.asList(25, 50, 75, 100, 125, 150);

现在,将整数列表转换为字符串列表 −

List<String> listString = listInteger.stream()
    .map(s -> String.valueOf(s))
    .collect(Collectors.toList());

以下是 Java 中将整数列表转换为字符串列表的程序 −

示例

import java.util.*;
import java.util.stream.*;
import java.util.function.*;
public class Demo {
   public static void main(String[] args) {
      List<Integer> listInteger = Arrays.asList(25, 50, 75, 100, 125, 150);
      System.out.println("List of Integer = " + listInteger);
      List<String> listString = listInteger.stream()
         .map(s -> String.valueOf(s))
         .collect(Collectors.toList());
      System.out.println("List of String (converted from List of Integer) = " + listString);
   }
}

输出

List of Integer = [25, 50, 75, 100, 125, 150]
List of String (converted from List of Integer) = [25, 50, 75, 100, 125, 150]

相关文章