List转为String数组 List对象.toArray(new String[0])
List转为String数组 List对象.toArray(new String[0])
private String[] getStringArray() {
return new String[]{"one", "two", "three"};
}
@Test
public void testConvertListToStringArray() {
String[] indices = getStringArray();
List<String> indicesList = Arrays.stream(indices).map(e -> "prefix_" + e).collect(Collectors.toList());
String[] indicesArray = indicesList.toArray(new String[0]);
System.out.println(Arrays.toString(indicesArray));
}
测试输出结果:
[prefix_one, prefix_two, prefix_three]