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]
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言开发
C++
C#
MongoDB
MySQL
JavaScript
PHP