要在一列中插入7个值,您可以使用逗号分隔符,如下所示:
其中Total_Score_P1是一个字符串数组
//字符串数组
String[] Total_Score = new String[] { p1e1,p1e2,p1e3,p1e4,p1e5,p1e6 };
String result_ScoreP1 = ("" + Arrays.asList(Total_Score_P1)).
replaceAll("(^.|.$)", " ").replace(", ", " , " );
result_ScoreP1将是:
//这个的输出
result_ScoreP1 = "p1e1,p1e2,p1e3,p1e4,p1e5,p1e6"
将其作为单个字符串插入数据库中,再次检索时将其分解成部分,例如:
//一个字符串数组列表
//查询被触发
public ArrayList<String> rulTable(String id) {
ArrayList<String> Ruleob = new ArrayList<String>();
Cursor c_rule;
try
{
c_rule = db.query(NameTable, new String[]{
columns1
},
Rule_COurseID + "=" + id ,
null, null,
null, null, null);
c_rule.moveToFirst();
if (!c_rule.isAfterLast())
{
do
{
Ruleob.add(c_rule.getString(0));
}
while (c_rule.moveToNext());
}
c_rule.close();
}
catch(Exception e)
{
}
return Ruleob;
}
ArrayList<String> ListOne = new ArrayList<String>();
ArrayList<String> row ;
try{
row = db.TheTable(id);
String r1 = row .get(0);
}
catch(Exception e)
{
}
StringTokenizer st2 = new StringTokenizer(r1, "||");
while(st2.hasMoreTokens()) {
String Desc = st2.nextToken();
System.out.println(Desc+ "\t" );
ListOne.add(Desc);
}