首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用sqlite android将数组转换为字符串格式

使用sqlite android将数组转换为字符串格式
EN

Stack Overflow用户
提问于 2017-12-19 22:56:18
回答 1查看 158关注 0票数 0

我正在将数组列表值保存到sq-lite数据库中。我在循环1,2之后,循环[1,2]之前将值转换为这种格式,但我希望在循环中获得值,如下所示:

代码语言:javascript
复制
1
2

这样做的正确方法是什么?

这是我的代码,这是我将arraylist值保存到数据库中的地方

代码语言:javascript
复制
    public ArrayList<String> getpid (int id){
    sqLiteDatabase =this.getReadableDatabase();
    ArrayList<String> list=new ArrayList<>();
    String sql="select p_id from cart where customer_id = '" + id + "' ";
    Cursor cursor=sqLiteDatabase.rawQuery(sql,null);
    if (cursor.moveToFirst()) {
        do {
            String idd = cursor.getString(0);
            String pid = cursor.getString(cursor.getColumnIndex("p_id"));
            list.add(pid);
            System.out.println("===pid"+pid);
        } while (cursor.moveToNext());
    }return list;

这段代码中,我试图将值一个接一个地转换为字符串格式

代码语言:javascript
复制
enter code here  ArrayList<String> arrayList=mydatabase.getpid(idd);
    System.out.println("--outside"+arrayList);
    for(int i =0; i<arrayList.size(); i++){

        String value=arrayList.get(i).toString();
        System.out.println("---size"+value);

    }
EN

回答 1

Stack Overflow用户

发布于 2017-12-19 23:57:52

首先,使用.toString将数组列表转换为字符串。然后将它的“,”替换为“”。如果要删除'[]‘符号,请将'’替换为"“,将'‘替换为"”。

代码语言:javascript
复制
ArrayListString.replace(',',' ') //Comma replace by space symbol. Also you can remove other symbols by using this method.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47889639

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档