数组列表未正确拆分 [英] Array list not getting split properly
本文介绍了数组列表未正确拆分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
值
ALL || test>测试已完成>测试再次完成||测试>测试已完成>测试再次完成2
是一个数组列表
The value ALL||test > test's done> test's done again's done||test > test's done> test's done again's done 2 is an array list
我要做的是用||
所以第一个元素是:
ALL
秒:
test > test's done> test's done again's done
最后一次:
last:
test > test's done> test's done again's done 2
我写的代码:
String record1 = record.toString();
String[] parts = record1.split("||");
for (int i = 1; i <= parts.length; i++) {
System.out.println(parts[i]);
}
我得到的是每个字母本身,最后是一个]
字符,它也是不需要的。
What i'm getting is each letter by itself and at the end a ]
character which is unwanted as well.
推荐答案
您可以使用以下代码进行拆分:
You can split by using the following code:
String [] parts = record1.split("\\|\\|");
此外,由于循环从1到parts.length而不是0到parts.length-1。
Also, the code written above won't work as the loop is running from 1 to parts.length instead of 0 to parts.length-1.
这篇关于数组列表未正确拆分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文