转换列表<对象>到 Java 中的 String[] [英] Convert List<Object> to String[] in Java
本文介绍了转换列表<对象>到 Java 中的 String[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从 List
转换为 String[]
.
I need to convert from List<Object>
to String[]
.
我做了:
List<Object> lst ...
String arr = lst.toString();
但我得到了这个字符串:
But I got this string:
["...", "...", "..."]
只是一个字符串,但我需要 String[]
is just one string, but I need String[]
非常感谢.
推荐答案
您必须遍历列表并填写您的 String[]
.
You have to loop through the list and fill your String[]
.
String[] array = new String[lst.size()];
int index = 0;
for (Object value : lst) {
array[index] = (String) value;
index++;
}
如果列表是 String
值,则列表就像调用 lst.toArray(new String[0])
;
If the list would be of String
values, List then this would be as simple as calling lst.toArray(new String[0])
;
这篇关于转换列表<对象>到 Java 中的 String[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文