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


这是我们的整数列表 −

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]

更新日期: 2019-09-23

607 次查看

开启你的 职业生涯

完成课程获得认证

开始
广告
© . All rights reserved.