首先创建一个List字符串:
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("\nUppercase 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