• 去除java list 中的 [] 括号


    项目中经常遇到

    java 后台 list中的数据要通过json 传入到前台页面中

    这时 就需要去除 list中给我加上的 [] 。

    方法如下

    1.重写 AbstractCollection类的toString 方法

    private String toString(Collection collection){
            StringBuffer stringbuffer = new StringBuffer();
            Iterator iterator1 = collection.iterator();
            boolean flag = iterator1.hasNext();
            do
            {
                if(!flag)
                    break;
                Object obj = iterator1.next();
                stringbuffer.append(obj != this ? String.valueOf(obj) : "(this Collection)");
                flag = iterator1.hasNext();
                if(flag)
                    stringbuffer.append(",");
            } while(true);
            return stringbuffer.toString();
        }

    2.或者使用 org.apache.commons.lang.StringUtils 

    StringUtils.strip( "['a','b','c','d']", "[]"); 
  • 相关阅读:
    情人节玫瑰花
    Yii2美化confirm
    apache ab压力测试
    Yii2的Debug工具
    yii2的扩展程序包
    slim
    composer使用
    打印
    yii的csv导出
    ajax文件下载
  • 原文地址:https://www.cnblogs.com/yehshuai/p/3613751.html
Copyright © 2020-2023  润新知