JAVA 数组或List连接成字符串

    /**
     * 连接方法 类似于javascript
     * @param join 连接字符串
     * @param strAry 需要连接的集合
     * @return
     */
    public static String join(String join,String[] strAry){
        StringBuffer sb=new StringBuffer();
        for(int i=0,len =strAry.length;iif(i==(len-1)){
                sb.append(strAry[i]);
            }else{
                sb.append(strAry[i]).append(join);
            }
        }
        return sb.toString();
    }

    /**
     * 将结果集中的一列用指定字符连接起来
     * @param join 指定字符
     * @param cols 结果集
     * @param colName 列名
     * @return
     */
    public static String join(String join,List cols,String colName){
        List aColCons = new ArrayList();
        for (Map map:
             cols) {
            aColCons.add(ObjectUtils.toString(map.get(colName)));
        }
        return join(join,aColCons);
    }

    public static String join(String join,List listStr){
        StringBuffer sb=new StringBuffer();
        for(int i=0,len =listStr.size();iif(i==(len-1)){
                sb.append(listStr.get(i));
            }else{
                sb.append(listStr.get(i)).append(join);
            }
        }
        return sb.toString();
    }

你可能感兴趣的:(JAVA)