打印列表

时间:2015-10-26 04:27:23

标签: java collections

       private String getQuery() {
                StringBuilder sb = new StringBuilder();

                sb.append(" SELECT DISTINCT col1,   ");
                sb.append("   col2, ");
                sb.append("   col3, ");
                sb.append("   col4, ");
                sb.append("   col5, ");.....so on 
                return sb.toString();


    public List<Object[]> getDetails(Connection connection, String RequestId) throws Exception {
            List<Object[]> test = null;
            final Map<Integer, Object> testMap = new HashMap<Integer, Object>();
            testMap.put(1, RequestId);
            test = executeQuery(connection, getQuery(), testMap, 100);
            return test; 
}

我想打印清单。我正在提供

System.out.println(test.toString());

然后是toString()覆盖方法,但它仍在打印地址。

我正在尝试打印如下 -

    System.out.println(test.toString());

@Override
    public String toString() {
        return "className [getQuery()=" + getQuery() + "]";
    }

1 个答案:

答案 0 :(得分:0)

打印对象值的示例程序

public static void main(String[] args){

        List<Object[]> list = new ArrayList<Object[]>();
        Object[] object1 = { 2, 3 };
        Object[] object2 = { 5, 8 };
        list.add(object1);
        list.add(object2);
        System.out.println(list.toString()); // prints address here

        for (Object[] myArray : list) {
            for (Object obj : myArray) {
                System.out.println(obj); // print elements
            }
        }
    }

<强>输出

[[Ljava.lang.Object;@659e0bfd, [Ljava.lang.Object;@2a139a55]
2
3
5
8