如何在 Java 中将列表字符串转换为大写?


我们先创建一个列表字符串

List<String> list = Arrays.asList("David", "Tom", "Ken","Yuvraj", "Gayle");

现在将上面的列表转换为大写

list.stream().map(players -> players.toUpperCase())

要进行显示,请使用 forEach()

list.stream().map(players -> players.toUpperCase()) .forEach(players -> System.out.print(players + ""));

以下是将列表字符串转换为大写的示例

示例

import java.util.Arrays;
import java.util.List;
public class Demo {
   public static void main(final String[] args) {
      List<String> list = Arrays.asList("David", "Tom", "Ken","Yuvraj", "Gayle");
      System.out.print("List = "+list);
      System.out.print("
Uppercase strings = ");       list.stream().map(players -> players.toUpperCase()) .forEach(players -> System.out.print(players + ""));    } }

输出

List = [David, Tom, Ken, Yuvraj, Gayle]
Uppercase strings = DAVID TOM KEN YUVRAJ GAYLE

更新于:30-Jul-2019

3K+ 浏览量

启动您的 事业

通过完成课程获得认证

开始
广告
© . All rights reserved.