Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 转换列表下的元素<;字符串[]>;一气呵成_Java_String - Fatal编程技术网

Java 转换列表下的元素<;字符串[]>;一气呵成

Java 转换列表下的元素<;字符串[]>;一气呵成,java,string,Java,String,我正在使用一个带有几个较小大小写字段的列表 List<String[]> csvBody = reader.readAll(); List csvBody=reader.readAll(); 我的输出应该是相同的数据类型List 是否有可能将容器中的每个字符串在一段时间内转换为大写 我认为您可以使用列表#replaceAll和流的组合来映射数组: csvBody.replaceAll(a -> Arrays.stream(a)

我正在使用一个带有几个较小大小写字段的
列表

List<String[]> csvBody = reader.readAll();
List csvBody=reader.readAll();
我的输出应该是相同的数据类型
List


是否有可能将容器中的每个字符串在一段时间内转换为大写

我认为您可以使用
列表#replaceAll
的组合来映射数组:

csvBody.replaceAll(a -> Arrays.stream(a)
                              .map(String::toUpperCase)
                              .toArray(String[]::new));

只需迭代字符串:

List<String[]> csvBody = reader.readAll();
for (String[] strings : csvBody) {
    for (int i = 0; i < strings.length; i++) {
        strings[i] = strings[i].toUpperCase();
    }
}
List csvBody=reader.readAll();
对于(字符串[]字符串:csvBody){
for(int i=0;i
列表结果=csvBody.stream()
.map(字符串->数组.stream(字符串)
.map(字符串::toUpperCase)
.toArray(字符串[]::新建))
.collect(Collectors.toList());

它创建一个
String[]
流,将每个字符串转换为大写,并返回一个包含(大写)字符串的数组。最后,将单个字符串[]收集到一个新列表中

如果您不需要保留原始字符串版本,我认为最简洁、最简单的方法是在从
阅读器

String line = reader.readLine().toUppercase();
如果您想保留原始字符串,这样做会有所帮助:

   list.stream().map(a -> Arrays.stream(a).map(String::toUppercase).toArray(String[]::new))
                .collect(Collectors.toList());

你的输出结构是什么?仍然
列表
?是否要保留字符串的原始非大写版本?我已更新了答案Manh。请参考。非常感谢您的回复。成功了!根据响应时间接受Jacob.G的回答。@Mike如果你关心速度,Neng的回答会比我的快。你真是Jacob。我要和能一起去!非常感谢您的回复。成功了!根据回复时间接受Jacob.G的回答。非常感谢您的回复。雅各布成功了。接受你的回答。非常感谢你的回复。我希望保留原来的版本!根据响应时间接受刘能的回答。
   list.stream().map(a -> Arrays.stream(a).map(String::toUppercase).toArray(String[]::new))
                .collect(Collectors.toList());