我有一个字符串category =“1-4-5-10-13-27-28-29-32-34-35-36-51-58-150”,我想转换成字符串数组将字符串转换为字符串数组
我已经尝试过这样的代码:
List<String> oldCat = new ArrayList<String>(Arrays.asList(category.split(",")));
,但它不工作
我有一个字符串category =“1-4-5-10-13-27-28-29-32-34-35-36-51-58-150”,我想转换成字符串数组将字符串转换为字符串数组
我已经尝试过这样的代码:
List<String> oldCat = new ArrayList<String>(Arrays.asList(category.split(",")));
,但它不工作
试试这个:
String category = "1-4-5-10-13-27-28-29-32-34-35-36-51-58-150";
String [] categoryArray = category.split("-");
然后,如果你要结束了用ArrayList<String>
做:
List<String> categoryArrayList = new ArrayList<String>();
Collections.addAll(categoryArrayList, categoryArray);
我想你想把字符串拆分成字符串。试试这个
String[] ary = category.split("-");
这将返回数组
@Pshemo更新 – Fahim 2015-02-24 02:23:44
你怎么看'分裂( “”)'呢? '列表'不是字符串数组。预期结果的后期例子。 –
Pshemo
2015-02-24 02:03:43
该代码的任何部分如何帮助您实现目标? – 2015-02-24 02:03:48
对不起。我已经得到了这个。在我的分裂中,它不应该像这样(“,”)而是这个(“ - ”)。我很抱歉家伙 – 2015-02-24 03:06:54