我有一个包含列表的字符串,我的意思是:
String list = "[\"hello\",\"everyone\"]";
如何对其进行转换,以便将其视为String[]
?我的问题可能不是很清楚,但请理解英语不是我的母语,谢谢大家。
答案 0 :(得分:0)
您可以使用replace
类的split
和String
方法来执行此操作,例如:
String s = "[\"hello\",\"everyone\"]";
String[] split = s.replace("[", "").replace("]", "").split(",");
System.out.println(Arrays.toString(split));
答案 1 :(得分:0)
public static void main(String... args) {
String [] strArray = new String [] {"hello","everyone"};
System.out.println(Arrays.toString(strArray));
}
答案 2 :(得分:0)
<强>进口:强>
local function onRowTouchTable(event)
local row = event.target
local id = row.index -- or row.id I'm not sure
print(myData[id])
end
<强>代码:强>
import java.util.Arrays;
import java.util.List;
<强>输出:强>
public static void main(String args[]) {
String input = "[\"hello\",\"everyone\"]"; // This is the input String
input = input.replace("[", "").replace("]", "").replace("\\", "").replace("\"", ""); // Remove
// the
// following
// characters:
// [
// ]
// \
// "
String splitOn = ", "; // The string will split whenever this pattern
// occurs
List<String> output = Arrays.asList(input.split(splitOn)); // Split on
// the
// String
System.out.println(output); // Output the result
}