用Java怎么将["png/2024/10/14/2747b2bf-74c7-44d2-b7f0-3671a6fba26e.png","png/2024/10/14/1e7800af-779e-47f7-82a1-6f423d2abafd.png"]转List<String>
时间: 2024-10-16 13:20:20 浏览: 27
IS903-A5量产工具V112(东芝-铠侠 SLC闪存 7S2F/6S2F/5S2F 专用)
在Java中,你可以使用ArrayList或者LinkedList来存储字符串数组。这里是一个简单的例子,展示如何将给定的字符串数组转换为List<String>:
```java
import java.util.ArrayList;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
String[] imagePaths = {"png/2024/10/14/2747b2bf-74c7-44d2-b7f0-3671a6fba26e.png", "png/2024/10/14/1e7800af-779e-47f7-82a1-6f423d2abafd.png"};
// 使用ArrayList进行转换
ArrayList<String> list = new ArrayList<>(Arrays.asList(imagePaths));
System.out.println(list);
// 输出:[png/2024/10/14/2747b2bf-74c7-44d2-b7f0-3671a6fba26e.png, png/2024/10/14/1e7800af-779e-47f7-82a1-6f423d2abafd.png]
// 或者使用LinkedList,效果类似
LinkedList<String> linkedList = new LinkedList<>(Arrays.asList(imagePaths));
System.out.println(linkedList);
}
}
```
阅读全文