Java List Print printQueryResults(List res)

Here you can find the source of printQueryResults(List res)

Description

Convenience method for printing query results.

License

Apache License

Parameter

Parameter Description
res Query results.

Declaration

public static void printQueryResults(List<?> res) 

Method Source Code

//package com.java2s;
/*//from   ww w. j av  a  2s  .co m
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.List;

public class Main {
    /**
     * Convenience method for printing query results.
     *
     * @param res Query results.
     */
    public static void printQueryResults(List<?> res) {
        if (res == null || res.isEmpty())
            System.out.println("Query result set is empty.");
        else {
            for (Object row : res) {
                if (row instanceof List) {
                    System.out.print("(");

                    List<?> l = (List) row;

                    for (int i = 0; i < l.size(); i++) {
                        Object o = l.get(i);

                        if (o instanceof Double || o instanceof Float)
                            System.out.printf("%.2f", o);
                        else
                            System.out.print(l.get(i));

                        if (i + 1 != l.size())
                            System.out.print(',');
                    }

                    System.out.println(')');
                } else
                    System.out.println("  " + row);
            }
        }
    }
}

Related

  1. printMap(HashMap> listHashMap)
  2. printNonEmptyList(List list)
  3. printObjectList(List list)
  4. printout(List record)
  5. printPerformanceStats(String message, List iterationTimesInNanoseconds)
  6. printRules(List rules, Class clazz)
  7. printStats(final List shocktimes)
  8. printStringList(List list, String name)
  9. printStringList(List listToPrint)

  10. HOME | Copyright © www.java2s.com 2016